从指定日期到现在,按年份分组的月份数组的最有效方法是什么。
例如 getMonths("August 2012") 将输出
array(
array("Year"=>"2013", "months" = array(
"February", "January")
),
array("Year"=>"2012", "months" = array(
"December", "November","October", "September", "August")
)
)
到目前为止,我有:
$start = strtotime('2012-08-01');
$end = time();
$month = $start;
$months[] = date('F', $start);
while($month <= $end) {
$month = strtotime("+1 month", $month);
$months[] = date('F', $month);
}
这是输出正确的月份,但没有将它们分组为年份。谢谢