我知道这个问题真的很可怜,我只是犯了一个我无法意识到的大错误。我想加载一个带有日期的数组。我有开始日期和结束日期。这是我的代码:
$year_from=2011;
$month_from=1;
$year_till=2012;
$month_till=5;
$array=array();
$year=$year_from;
$month=$month_till;
while($year!=$year_till and $month!=$month_till){
$array[]=$year.'-'.$month;
if($month==12){
$month=1;
$year=$year+1;
}else{
$month=$month+1;
}
}
print_r($array);
该脚本的输出如下:
Array ( [0] => 2011-1 [1] => 2011-2 [2] => 2011-3 [3] => 2011-4 [4] => 2011-5 [5] => 2011-6 [6] => 2011-7 [7] => 2011-8 [8] => 2011-9 [9] => 2011-10 )
请帮助我知道这是一项非常简单的任务,但它让我发疯。非常感谢任何帮助。
编辑:
期望的输出:
Array ( [0] => 2011-1 [1] => 2011-2 [2] => 2011-3 [3] => 2011-4 [4] => 2011-5 [5] => 2011-6 [6] => 2011-7 [7] => 2011-8 [8] => 2011-9 [9] => 2011-10 [10] => 2011-11 [11] => 2011-12 [12] => 2012-1 [13] => 2012-2 [14] => 2012-3 [15] => 2012-4 )