-1

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?

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63

1 Answers1

1

You're not using usort; you're using uasort. uasort keeps keys, usort will make new keys.

http://php.net/manual/en/function.usort.php

twentylemon
  • 1,248
  • 9
  • 11