Home > Backend Development > PHP Tutorial > 数组按照时间排序

数组按照时间排序

WBOY
Release: 2016-06-20 12:43:02
Original
976 people have browsed it

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

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        ))
Copy after login


回复讨论(解决方案)

foreach($arr as $v) $r[] = $v['created_time'];
array_multisort($r, SORT_DESC, $arr);
$ar = array_slice($arr, 0, 6);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template