How to have a stable sort in PHP with arsort()?

后端 未结 7 712
迷失自我
迷失自我 2020-12-03 22:40

i need to sort an array in php based on value, array use some numbers for keys and values, for example like this:

$a = array(70 => 1 ,82          


        
7条回答
  •  情话喂你
    2020-12-03 23:13

    This is because the sort family of functions are not stable. If you need the sort to be stable then you either have to implement it yourself, or iterate over the sorted result and "correct" the positions of the elements using array_splice.

提交回复
热议问题