排序前
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),其他数组(可以是二维的))
总结
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理