This article mainly introduces the example code of PHP two-dimensional associative array sorting according to one of the fields. It is very good and has reference value. Friends in need can refer to
How to use two-dimensional associative arrays in PHP To sort according to one of the fields, the following code sorts the two-dimensional associative array $array according to the $orderby field:
function wpjam_array_multisort($array, $orderby, $order = SORT_ASC, $sort_flags = SORT_NUMERIC){ $refer = array(); foreach ($array as $key => $value) { $refer[$key] = $value[$orderby]; } array_multisort($refer, $order, $sort_flags, $array); return $array; }
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
bind_param() function usage analysis in php
PHPAnalysis of the method of creating an empty object using new StdClass()
ThinkPHP 3.2.2 Methods to implement transaction operations
The above is the detailed content of How to sort a two-dimensional associative array in PHP according to one of its fields. For more information, please follow other related articles on the PHP Chinese website!