php 获取当前24个月月份

    // 获取二十四个月份
     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);

 

posted @ 2015-12-14 16:17  不会r闪怪腾讯  阅读(272)  评论(0编辑  收藏  举报