问题
I have an array which looks like this:
$arr = ( [0]=>Int(2)
[1]=>Array( ....)
[2]=>Array( ....)
[3]=>Array( ....))
I have used usort to sort it:
usort($arr,function($a, $b) {
if($a['prop'] == $b['prop']) return 0;
return ($a['prop'] < $b['prop']) ? 1 : -1;
});
My problem is that the key [0] is rewritten with an Array element. Don't get me wrong...it's suppose to. How could i sort the $arr array without rewrite the key [0] ?
回答1:
just use uasort()
http://php.net/manual/en/function.uasort.php
来源:https://stackoverflow.com/questions/11276366/sort-an-array-without-rewriting-a-key