时间:2021-07-01 10:21:17 帮助过:12人阅读
$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)