how to sort a multidemensional array by an inner key

后端 未结 6 1073
你的背包
你的背包 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 02:57

    You can use array_multisort for this: first provide the column you want to sort -- with array_column and as second argument the whole array. There are several options possible (see documentation), but for an ascending sort by the "rank" field, it would look like this:

    array_multisort(array_column($players, "rank"), $players);
    

    NB: For the data in the actual question here, $players would be &$arr["players"]

提交回复
热议问题