开发者

Calculate number of days in each month for a given year using PHP [duplicate]

This question already has answers here: Closed 10 years ago.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜