PHP implementation of the specified field of multidimensional array sorting function sharing, multidimensional array
The PHP array sort can be implemented with 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 ordering method for a specified field in PHP, which can be sorted by an array of field fields.
Copy the Code code 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 PHP code to help you.
http://www.bkjia.com/PHPjc/965357.html www.bkjia.com true http://www.bkjia.com/PHPjc/965357.html techarticle PHP Implementation of the specified field of multi-dimensional array sorting function sharing, multidimensional array of PHP array ordering can be implemented with the Array_multisort method, but if it is a multidimensional array, and we want to specify the array ...