Calculate number of days in each month for a given year using PHP [duplicate]
Possibl开发者_JS百科e Duplicate:
PHP iterate days of month given month and year
How can I calculate number of days in each month for a given year?
read this cal_days_in_month
Return the number of days in a month for a given year and calendar
To do this I created a function as below:
// Calculate number of days in each month for a given year.
function getDays($year){
$num_of_days = array();
$total_month = 12;
if($year == date('Y'))
$total_month = date('m');
else
$total_month = 12;
for($m=1; $m<=$total_month; $m++){
$num_of_days[$m] = cal_days_in_month(CAL_GREGORIAN, $m, $year);
}
return $num_of_days;
}
$num_of_days = getDays('2011');
print_r($num_of_days);
精彩评论