Home >Backend Development >PHP Tutorial >PHP method to sort multi-dimensional array according to a certain field_PHP tutorial
This article mainly introduces the method of sorting multi-dimensional arrays in PHP based on a certain field, and analyzes PHP array operations with examples. and sorting skills, which has certain reference value. Friends in need can refer to it
The example in this article describes how PHP sorts multi-dimensional arrays based on a certain field. Share it with everyone for your reference. The specific analysis is as follows:
Sort multi-dimensional arrays according to a certain field. When I saw the role of the array_multisort method, I suddenly thought that this method could be used
This code can sort the array according to the field field
?
3 4 5
|
function sortArrByField(&$array, $field, $desc = false){
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = $v[$field];
} |