主要通过 array_multisort 函数来进行排序
<?php
//原数组
$arr = [
["name"=>"小明","age"=>18],
["name"=>"小红","age"=>7],
["name"=>"小刚","age"=>52],
["name"=>"小亮","age"=>33],
];
//将元素组的需排序的字段获取出来
$column = array_column($arr,"age");
//进行排序
array_multisort($column,SORT_DESC,$arr);
var_dump($arr);
结果如下
标签:排序,name,int,age,二维,array,php,string From: https://blog.51cto.com/u_15668841/6546678
array(4) { [0]=> array(2) { ["name"]=> string(6) "小刚" ["age"]=> int(52) } [1]=> array(2) { ["name"]=> string(6) "小亮" ["age"]=> int(33) } [2]=> array(2) { ["name"]=> string(6) "小明" ["age"]=> int(18) } [3]=> array(2) { ["name"]=> string(6) "小红" ["age"]=> int(7) } }