php二维数组按某个键值排序的实例讲解
程序员文章站
2023-11-14 14:01:34
排序前
array
(
[0] => array
(
[name] => 龙
[age] => 2...
排序前
array ( [0] => array ( [name] => 龙 [age] => 2017-02-28 ) [1] => array ( [name] => 龙2 [age] => 2017-03-14 ) [2] => array ( [name] => 小3 [age] => 2017-05-09 ) [3] => array ( [name] => 龙4 [age] => 2017-02-03 ) [4] => array ( [name] => 龙5 [age] => 2017-03-23 ) [5] => array ( [name] => 龙6 [age] => 21 ) ) array_multisort(array_column($arr,'age'),sort_desc,$arr); print_r($arr);
排序后
array ( [0] => array ( [name] => 龙6 [age] => 21 ) [1] => array ( [name] => 小3 [age] => 2017-05-09 ) [2] => array ( [name] => 龙5 [age] => 2017-03-23 ) [3] => array ( [name] => 龙2 [age] => 2017-03-14 ) [4] => array ( [name] => 龙 [age] => 2017-02-28 ) [5] => array ( [name] => 龙4 [age] => 2017-02-03 ) )
其中 array_column(数组,数组中的某个键值) 从多维数组中取出某个键值的一列 返回一个一维数组;
array_multisort(数组(一维数组),排序方式(sotr_asc,sotr_desc),其他数组(可以是二维的))
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
上一篇: .NET工厂方法模式讲解