實作中使用的第一個遞迴函數,原始碼如下:
function get_lastN_period($n,$year,$month){
$year=date(“Y”,mktime(0,0,0,$month-2,1,$year));
$month=date(“n”,mktime(0,0,0,$month-2,1,$year));
if($n==1){
return array(get_preperiod_month($year,$month));
}
return array_merge(array(get_preperiod_month($year , $month)), get_lastN_period($n-1 , $year , $month));
}