首頁 >後端開發 >php教程 >数组按照时间排序

数组按照时间排序

WBOY
WBOY原創
2016-06-20 12:43:02982瀏覽

有如下数组 我想按照时间降序  获取最新的六条数据  代码如下:

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);

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn