This question already has an answer here:
- How do you reindex an array in PHP? 19 answers
I have a 2d array like this :
array (size=3)
0 =>
array (size=2)
'player_id' => string '26' (length=2)
'score' => float 4.702030124427
1 =>
array (size=2)
'player_id' => string '27' (length=2)
'score' => float 17.891873624039
2 =>
array (size=2)
'player_id' => string '29' (length=2)
'score' => float 17.883449353824
I'm using usort to sort it and it becomes like this:
array (size=3)
1 =>
array (size=2)
'player_id' => string '27' (length=2)
'score' => float 17.891873624039
2 =>
array (size=2)
'player_id' => string '29' (length=2)
'score' => float 17.883449353824
0 =>
array (size=2)
'player_id' => string '26' (length=2)
'score' => float 4.702030124427
my usort function is this:
uasort($scoreList,function($a, $b) {
if($a['score']==$b['score']) return 0;
return $a['score'] < $b['score']?1:-1;
});
is there any way I can overwrite the indexes so the sorted list becomes 0,1,2 instead of 1,2,0?
</div>