首页 > 后端开发 > php教程 > 数组按照时间排序

数组按照时间排序

WBOY
发布: 2016-06-20 12:43:02
原创
970 人浏览过

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

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

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板