最新消息: 新版网站上线了!!!

php 循环日期的函数

<?php
function timeList($beginTimeStamp,$endTimeStamp){
    if(!is_numeric($beginTimeStamp)||!is_numeric($endTimeStamp)||($endTimeStamp<=$beginTimeStamp)) return '';
    $tmp=array();
    for($i=$beginTimeStamp;$i<=$endTimeStamp;$i+=(24*3600)){
        //$tmp['dayList'][]= strtotime(date('Y-m-d',$i));
        $tmp['dayList'][]= date('Y-m-d',$i);

    }
    return $tmp;
}
$list = timeList(time(),strtotime('+10 days'));
print_r($list);
/*

Array
(
    [dayList] => Array
        (
            [0] => 2016-09-09
            [1] => 2016-09-10
            [2] => 2016-09-11
            [3] => 2016-09-12
            [4] => 2016-09-13
            [5] => 2016-09-14
            [6] => 2016-09-15
            [7] => 2016-09-16
            [8] => 2016-09-17
            [9] => 2016-09-18
            [10] => 2016-09-19
        )

)
*/

转载请注明:谷谷点程序 » php 循环日期的函数