dpg98445 2015-05-19 15:06
浏览 39
已采纳

按特定级别索引重新排列数组顺序

I have been searching this but did not find any solution anywhere. I want to re order my array with a specific index.

Like this:

$scoreboard = array(
    'foo' => array(
        'score' => 580,
        'game' => 'google',
    ),
    'bar' => array(
        'score' => 1385,
        'game' => 'facebook',
    ),
    'car' => array(
        'score' => 750,
        'game' => 'tweet',
    ),
);

And the output should be like this:

$scoreboard = array(
    'bar' => array(
        'score' => 1385,
        'game' => 'facebook',
    ),
    'car' => array(
        'score' => 750,
        'game' => 'tweet',
    ),
    'foo' => array(
        'score' => 580,
        'game' => 'google',
    ),
);

See that the array is rearranged with each item's 'score' index. Any help here?

  • 写回答

2条回答 默认 最新

  • doutang7383 2015-05-19 15:19
    关注

    Expanding on on my comment where I suggested to use the uasort function, here is a working sample: http://codepad.org/fBSqHNCC

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏