Number of days in a given month and year. Typically used as a shortcut for generating a list that can be used in a form.
Date::days(4, 2010); // 1, 2, 3, ..., 28, 29, 30
array Core_Date::days( integer $month [, integer $year = bool false ] )
参数列表
参数 类型 描述 默认值 $month
integer
Number of month $year
integer
Number of year to check month, defaults to the current year bool false
array
A mirrored (foo => foo) array of the days.public static function days($month, $year = FALSE)
{
static $months = array();
if ( $year === FALSE )
{
// Use the current year by default
$year = date('Y');
}
// Always integers
$month = (int)$month;
$year = (int)$year;
// We use caching for months, because time functions are used
if ( empty($months[$year][$month]) )
{
$months[$year][$month] = array();
// Use date to find the number of days in the given month
$total = date('t', mktime(1, 0, 0, $month, 1, $year)) + 1;
for( $i = 1; $i < $total; $i ++ )
{
$months[$year][$month][$i] = (string)$i;
}
}
return $months[$year][$month];
}