Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

php - how to sort a multidemensional array by an inner key

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 for each soldier, however the API sormats it sorting the soldiers by name alphabetically, i want to sort them by rank (which is just another key within that soldiers array). ive been trying to figure this out for days, anyone have any ideas? (ie sort the array by $arr[players][][rank]

here is a bit of the array

Array
(
    [players] => Array
        (
            [0] => Array
                (
                    [name] => bigjay517
                    [rank] => 29
                    [rank_name] => SECOND LIEUTENANT II
                    [veteran] => 0
                    [score] => 979440
                    [level] => 169
                    [kills] => 4134
                    [deaths] => 3813
                    [time] => 292457.42
                    [elo] => 319.297
                    [form] => 1
                    [date_lastupdate] => 2010-03-30T14:06:20+02:00
                    [count_updates] => 13
                    [general] => Array
                        (
                            [accuracy] => 0.332
                            [dogr] => 86
                            [dogt] => 166
                            [elo0] => 309.104
                            [elo1] => 230.849
                            [games] => 384
                            [goldedition] => 0
                            [losses] => 161
                            [sc_assault] => 146333
                            [sc_award] => 567190
                            [sc_bonus] => 35305
                            [sc_demo] => 96961
                            [sc_general] => 264700
                            [sc_objective] => 54740
                            [sc_recon] => 54202
                            [sc_squad] => 53210
                            [sc_support] => 70194
                            [sc_team] => 21215
                            [sc_vehicle] => 44560
                            [slevel] => 0
                            [spm] => 0
                            [spm0] => 0
                            [spm1] => 0
                            [srank] => 0
                            [sveteran] => 0
                            [teamkills] => 67
                            [udogt] => 0
                            [wins] => 223
                        )

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can sort any array by any criteria using usort()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...