dsjk3214 2015-08-06 02:01
浏览 45
已采纳

在PHP中覆盖2d数组覆盖索引[重复]

This question already has an answer here:

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>
  • 写回答

1条回答 默认 最新

  • donglin4636 2015-08-06 02:04
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?