开始日期要与结束日期相差一个月以上:
$time1 = strtotime('2014-10-04'); //开始日期
$time2 = strtotime('2015-02-06'); //结束日期
$month = array(); //定义数组
$month[] = date('Y-m',$time1);
while( ($time1 = strtotime('+1 month', $time1)) <= $time2){
$month[] = date('Y-m',$time1); // 取得递增月;
}
print_r($month);
获取两个月直接的所有月是上面的升级版
$time1 = strtotime(date('Y-m-01',strtotime('2018-05-26'))); //开始日期
$time2 = strtotime(date('Y-m-01',strtotime('2018-06-06'))); //结束日期
$month = array(); //定义数组
$month[] = date('Y-m',$time1);
while( ($time1 = strtotime('+1 month', $time1)) <= $time2){
$month[] = date('Y-m',$time1); // 取得递增月;
}
print_r($month);