Sort an array without rewriting a key

本秂侑毒 提交于 2020-01-30 09:01:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!