how to sort a multidemensional array by an inner key

后端 未结 6 1083
你的背包
你的背包 2020-12-02 02:34

i have this enormous array that i am pulling from an API for BattleField Bad Company 2, and the soldier stats can be pulled as a multi dimensional array with an inner array

6条回答
  •  余生分开走
    2020-12-02 03:09

    Here you go.

    $playergoop is the array that you provided.

    This one sorts by the sub-field 'rank', but it does so in an ascending order. If you want a descending order, you can switch the > to <.

    function sorter($one, $two) {
        return ($one['rank'] > $two['rank']);
    }
    
    usort($playergoop['players'], sorter);
    

提交回复
热议问题