Rumah >pembangunan bahagian belakang >tutorial php >数组按照时间排序
有如下数组 我想按照时间降序 获取最新的六条数据 代码如下:
Array( [0] => Array ( [id] => 81 [title] => 撒大声地 [uid] => 166 [created_time] => 2015-11-25 17:15:27 [1] => 1 ) [1] => Array ( [id] => 80 [title] => 唐门提问问题标题一 [uid] => 166 [created_time] => 2015-11-20 14:49:57 [1] => 1 ) [2] => Array ( [id] => 22 [title] => test [uid] => 126 [created_time] => 2015-12-10 14:49:57 [2] => 2 ) [3] => Array ( [id] => 78 [title] => 123 [uid] => 122 [created_time] => 2015-11-16 15:52:19 [1] => 1 ) [4] => Array ( [id] => 77 [title] => dsfasd [uid] => 156 [created_time] => 2015-11-09 11:04:24 [1] => 1 ) [5] => Array ( [id] => 76 [title] => CE [uid] => 156 [created_time] => 2015-11-04 16:44:34 [1] => 1 ) [6] => Array ( [id] => 79 [title] => 测试 [uid] => 156 [created_time] => 2015-11-18 14:28:44 [1] => 1 ) [7] => Array ( [id] => 21 [title] => 没删除—1 [uid] => 126 [created_time] => 2015-07-02 13:50:44 [2] => 2 ) [8] => Array ( [id] => 20 [title] => 没删除—1 [uid] => 126 [created_time] => 2015-07-02 13:50:44 [2] => 2 ) [9] => Array ( [id] => 19 [title] => 没删除—1 [uid] => 126 [created_time] => 2015-07-02 13:50:44 [2] => 2 ) [10] => Array ( [id] => 18 [title] => 没删除—1 [uid] => 126 [created_time] => 2015-07-02 13:50:44 [2] => 2 ) [11] => Array ( [id] => 17 [title] => 1人撒Yui日体育规范地方发货方撒地方 [uid] => 3 [created_time] => 2015-07-02 13:50:44 [2] => 2 ))
foreach($arr as $v) $r[] = $v['created_time'];
array_multisort($r, SORT_DESC, $arr);
$ar = array_slice($arr, 0, 6);