//Q:从今天起之前五个月的列表
date_default_timezone_set('PRC');
$time=strtotime('-5 month'); //包含本月
$begin = strtotime(date('Y-m-01 00:00:00', $time));
$end = strtotime(date('Y-m-01 00:00:00') . ' +1 month -1 day');
if ($begin > $end) {
    die('开始时间不能大于结束时间!');
}
$motharr = array();
$format_month= array();

do{
    $motharr[] = date('Y-m', $begin);
    /* 获取月份间的开始结束时间 */
    $format_begin=date('Y-m-01 00:00:00', $begin);
    $format_end = date('Y-m-d 59:59:59',strtotime($format_begin.' +1 month -1 day'));
    $dtmp['fbegin'] = $format_begin;
    $dtmp['fend'] = $format_end;
    $format_month[]=$dtmp;
}while(($begin = strtotime('+1 month', $begin)) <= $end);
//$motharr[] = date('Y-m', ($begin));
//while (($begin = strtotime('+1 month', $begin)) <= $end) {
//    $motharr[] = date('Y-m', $begin);
//    /* 获取月份间的开始结束时间 */
//    $format_begin=date('Y-m-01 00:00:00', $begin);
//    $format_end = date('Y-m-d 59:59:59',strtotime($format_begin.' +1 month -1 day'));
//    $dtmp['fbegin'] = $format_begin;
//    $dtmp['fend'] = $format_end;
//    $format_month[]=$dtmp;
//}
arsort($motharr);   // 时间排序
print_r($motharr);
print_r($format_month);
die;