如何实现以半小时 每分钟为记录 如果没有记录的 自动转0
Array
(
[2015-12-02 11:33] => 0
[2015-12-02 11:34] => 0
[2015-12-02 11:35] => 0
[2015-12-02 11:36] => 1
[2015-12-02 11:37] => 0
[2015-12-02 11:38] => 2
[2015-12-02 11:44] => 1
..........................
)
如何实现就是没有记录的 自动添加时间且值为0? 求大神解救!!
回复讨论(解决方案)
$a = Array( '2015-12-02 11:44' => 1, '2015-12-02 11:36' => 1, '2015-12-02 11:38' => 2,);ksort($a);$t = intval(strtotime(key($a)) / 30 /60) * 30 * 60;for($i=0; $i<30; $i++, $t+=60) { $k = date('Y-m-d H:i', $t); $r[$k] = isset($a[$k]) ? $a[$k] : 0;}print_r($r);
Array( [2015-12-02 11:30] => 0 [2015-12-02 11:31] => 0 [2015-12-02 11:32] => 0 [2015-12-02 11:33] => 0 [2015-12-02 11:34] => 0 [2015-12-02 11:35] => 0 [2015-12-02 11:36] => 1 [2015-12-02 11:37] => 0 [2015-12-02 11:38] => 2 [2015-12-02 11:39] => 0 [2015-12-02 11:40] => 0 [2015-12-02 11:41] => 0 [2015-12-02 11:42] => 0 [2015-12-02 11:43] => 0 [2015-12-02 11:44] => 1 [2015-12-02 11:45] => 0 [2015-12-02 11:46] => 0 [2015-12-02 11:47] => 0 [2015-12-02 11:48] => 0 [2015-12-02 11:49] => 0 [2015-12-02 11:50] => 0 [2015-12-02 11:51] => 0 [2015-12-02 11:52] => 0 [2015-12-02 11:53] => 0 [2015-12-02 11:54] => 0 [2015-12-02 11:55] => 0 [2015-12-02 11:56] => 0 [2015-12-02 11:57] => 0 [2015-12-02 11:58] => 0 [2015-12-02 11:59] => 0)