// 获取二十四个月份 function allMonth($start,$end){ $startTime = strtotime($start.'01'); $monthArr = array(); $i=0; while (1) { $nowTime = strtotime('+'.$i.' month',$startTime); $month = date('Ym',$nowTime); if ($month>$end) { break; }else{ $monthArr[]= $month; } $i++; } return $monthArr; } $end = date('Ym',time()); $start = date('Ym',strtotime('-24 month',strtotime($end))); $result = allMonth($start,$end); echo '<pre>'; print_r($result);