PHP获取指定时间的前N个月

function to_last_month($num){
	$today = date("Y-m-d");
	
	$arr = array();
	$m = '-'.$num.' month';
	$old_time = strtotime($m,strtotime($today));
	for($i = 0;$i <= $num-1; ++$i){
		$t = strtotime("+$i month",$old_time);
		$arr[] = date('y年m月',$t);
	}
	//return $str = "'".str_replace( ",","','", implode(',',$arr))."'"; 
	return json_encode($arr);
}

  

posted @ 2019-03-12 16:52  风79  阅读(1143)  评论(0编辑  收藏  举报