php 二维数组按某个字段排序
主要用到两个函数:
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;
相关推荐
mingyunxiaohai 2020-07-28
zhoujiyu 2020-06-28
sasac 2020-09-25
huangjie0 2020-09-25
cloudking000 2020-09-11
xiaoxiaokeke 2020-07-28
honghao0 2020-07-27
风吹夏天 2020-07-26
夕加加 2020-07-20
CallmeZhe 2020-06-29
Happyunlimited 2020-06-15
wanff0 2020-06-14
cuiguanjun 2020-06-13
啸林 2020-06-12
jiayuqicz 2020-06-09
章鱼之家 2020-06-08
guangmingsky 2020-06-05
zcabcd 2020-06-03