Home  >  Article  >  Backend Development  >  Detailed explanation of array time sorting in php

Detailed explanation of array time sorting in php

小云云
小云云Original
2018-03-21 15:00:002558browse

This article mainly shares with you the detailed explanation of array time sorting in PHP. I hope it can help you.

Ideas: 1.2018-03-20 16:19:00 Format.

2.php function array_multisort(); Sorting

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

Print results:


相关推荐:
php 二维数组时间排序实现代码
<a href="http://www.php.cn/php-weizijiaocheng-310420.html" target="_self">PHP 远程文件管理,可以给表格排序,遍历目录,时间排序_PHP教程</a><br>

The above is the detailed content of Detailed explanation of array time sorting in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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