This article mainly introduces the PHP implementation of the specified field of multidimensional array sorting function sharing, this article shares a section of the PHP specified field of multidimensional array sorting method code, this code can be implemented according to the field of the array of groups to sort, the need for friends can refer to the
PHP array sorting can be implemented in the Array_multisort method, but if it is a multidimensional array, and we want to specify a field in the array to sort, then we need to write our own method implementation. This article shares the code for a multidimensional array sort method for a PHP-specified field that can be sorted by the array of field fields.
The code is as follows:
Function Sortarrbyfield (& $array, $field, $desc = False) {
$FIELDARR = Array ();
foreach ($array as $k => $v) {
$FIELDARR [$k] = $v [$field];
}
$sort = $desc = = False? Sort_asc:sort_desc;
Array_multisort ($FIELDARR, $sort, $array);
}
The above is the PHP specified field of multidimensional array sorting method, I hope this section of PHP code to bring you help.