1 /** 2 * 生成从开始月份到结束月份的月份数组 3 * 该方法仿照党子皓getDateArr()方法 4 * @param unknown_type $start 5 * @param unknown_type $end 6 */ 7 function getMonthArr($start, $end) 8 { 9 $start = empty($start) ? date('Y-m',strtotime('-1 month')) : $start; 10 $end = empty($end) ? date('Y-m') : $end; 11 12 //转为时间戳 13 $st = strtotime($start.'-01'); 14 $et = strtotime($end.'-01'); 15 16 $t = $st; 17 $i = 0; 18 while($t <= $et) 19 { 20 //这里累加每个月的的总秒数 计算公式:上一月1号的时间戳秒数减去当前月的时间戳秒数 21 //看不懂自己想去 22 $d[$i] = trim(date('Y-m',$t),' '); 23 $t += strtotime('+1 month', $t)-$t; 24 $i++; 25 } 26 return $d; 27 }
转载于:https://www.cnblogs.com/cntnn11/archive/2012/05/11/2496174.html