当前位置:Gxlcms > PHP教程 > php之数组时间排序详解

php之数组时间排序详解

时间:2021-07-01 10:21:17 帮助过:5人阅读

本文主要和大家分享php之数组时间排序详解,希望能帮助到大家。

思路:1.2018-03-20 16:19:00 格式。

2.php 函数 array_multisort(); 排序

$arr = array(    'a'=>array(           'uid'=>12,           'name'=>'zhangsan1',           'ctime'=>'2018-03-20 11:28:00'                ),    'b'=>array(        'uid'=>13,        'name'=>'zhangsan2',        'ctime'=>'2018-03-19 11:28:00'    ),    'v'=>array(        'uid'=>14,        'name'=>'zhangsan3',        'ctime'=>'2018-03-21 11:28:00'    ),    'c'=>array(        'uid'=>14,        'name'=>'zhangsan3',        'ctime'=>'2018-03-22 11:28:00'    ),);$ctime_str = array();foreach($arr as $key=>$v){    $arr[$key]['ctime_str'] = strtotime($v['ctime']);    $ctime_str[] = $arr[$key]['ctime_str'];}                                                array_multisort($ctime_str,SORT_DESC,$arr);   批注:$ctime_str 是第一个数组,类似于sql排序中的,先以谁为准,order by id,ctime  ||| $arr是第二个数组
print_r($arr);

打印结果:


相关推荐:
php 二维数组时间排序实现代码
PHP 远程文件管理,可以给表格排序,遍历目录,时间排序_PHP教程

以上就是php之数组时间排序详解的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行