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);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章