/** * @desc xmsb_multiSort PHP对多维数组内每个数组及其值进行排序 * @param array $originalArray 要排序的数组 * @param boolean $isReverse 是否为倒序 默认为false * @param boolean $keepKey 是否保留键值对应 默认为false */ function xmsb_multiSort($originalArray,$isReverse = false, $keepKey = false) { $isReverse ? arsort($originalArray) : asort($originalArray); if(count($originalArray) != count($originalArray, 1)) { function callback($array, $isReverse, $keepKey) { foreach($array as $arrKey => $arrValue) { if(is_array($arrValue)) { $isReverse ? arsort($arrValue) : asort($arrValue); $array[$arrKey] = $keepKey ? callback($arrValue, $isReverse, $keepKey) : callback(array_values($arrValue), $isReverse, $keepKey); } } return $array; } $newArray = $keepKey ? $originalArray : array_values($originalArray); return callback($newArray, $isReverse, $keepKey); } else { return $keepKey ? $originalArray : array_values($originalArray);; } }