本文主要和大家分享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 二维数组时间排序实现代码
<a href="http://www.php.cn/php-weizijiaocheng-310420.html" target="_self">PHP 远程文件管理,可以给表格排序,遍历目录,时间排序_PHP教程</a><br/>
以上就是php之数组时间排序详解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号