码迷,mamicode.com
首页 > 编程语言 > 详细

php 二维数组按某个字段排序

时间:2020-06-16 23:26:02      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:amp   path   字段   函数   数组   color   com   basename   sftp   

主要用到两个函数:

1.array_column() 返回输入数组中某个单一列的值。php版本5.5以后自带

2.array_multisort() 函数返回排序数组。您可以输入一个或多个数组。函数先对第一个数组进行排序,接着是其他数组,如果两个或多个值相同,它将对下一个数组进行排序。

<?php
$data = [[
    "path" => "sftp/outgoing/1234_20200201_bill(1).csv",
    "timestamp" => 1591669515,
    "type" => "file",
    "visibility" => "public",
    "size" => 765,
    "dirname" => "sftp/outgoing",
    "basename" => "1234_20200201_bill(1).csv",
    "extension" => "csv",
    "filename" => "1234_20210201_bill(1)",
], [
    "path" => "sftp/outgoing/1234_20200611_bill.csv",
    "timestamp" => 1591937136,
    "type" => "file",
    "visibility" => "public",
    "size" => 240,
    "dirname" => "sftp/outgoing",
    "basename" => "1234_20200611_bill.csv",
    "extension" => "csv",
    "filename" => "1234_20200611_bill",
]];
$last_names = array_column($data, ‘filename‘);
array_multisort($last_names, SORT_ASC, $data);//SORT_ASC 按照上升顺序排序, SORT_DESC 按照下降顺序排序

echo ‘<pre>‘;
print_r($data);
echo ‘<pre>‘;
exit;

 

参考:https://www.cnblogs.com/wenzheshen/p/9455554.html

php 二维数组按某个字段排序

标签:amp   path   字段   函数   数组   color   com   basename   sftp   

原文地址:https://www.cnblogs.com/clubs/p/13149780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!