cal_days_in_month
针对指定的年份和历法,返回一个月中的天数。
<h2>适用PHP版本</h2>
<p>PHP 4, PHP 5, PHP 7, PHP 8</p>
<h2>函数说明</h2>
<p>cal_days_in_month 函数返回一个指定日历类型和年份中指定月份的天数。</p>
<h2>函数语法</h2>
<p>cal_days_in_month(int $calendar, int $month, int $year): int
$calendar = CAL_GREGORIAN; // 使用公历
$month = 2; // 查询二月
$year = 2024; // 2024年
$days = cal_days_in_month($calendar, $month, $year);
echo "2024年2月有 " . $days . " 天。";
在这个示例中,我们查询的是公历(CAL_GREGORIAN)下,2024年2月的天数。由于2024年是闰年,2月有29天,因此输出将会是 "2024年2月有 29 天"。