结果是一个每半小时持续一次的数组

时间:2014-11-18 15:05:38

标签: php

我想做一个函数来给我一个时间范围的数组,如下所示:

// passing FROM, TO ( times to the function ) 
function time( '11:00', '13:00' ) {

}


// i want to get it like the following 
[ 0 => '11:00', 1 => '11:30', '2' => '12:00', 3 => '12:30', 4 => '01:00' and so on .... ]

我该怎么做?

1 个答案:

答案 0 :(得分:1)

$hourRange = range(strtotime('00:00'), strtotime('23:50'), 10 * 60);

foreach($hourRange as $time){
    $date = date("H:i",$time);
    echo $date . "\n";
}

https://gist.github.com/adililhan/cc172f0eed55f6968b10