kristian
kristian

Reputation: 213

Different position of my array

Im currently in the making of a website, to show of LoL Stats, but here comes the tricky one ^^.

When I try to get the stats, not all players have played all the different game modes, so lets say, that

Player 1, has played only one game mode, so the array would look like this:

[0] => Array
           (
                [playerStatSummaryType] => Unranked
                [wins] => 141
                [losses] => 0
                [modifyDate] => 1389338360000
                [aggregatedStats] => Array
                    (
                        [totalChampionKills] => 1114
                        [totalMinionKills] => 36216
                        [totalTurretsKilled] => 287
                        [totalNeutralMinionsKilled] => 2265
                        [totalAssists] => 1923
                    )

            )

Then player 2, have played 3 game modes, then it would like look this.

[0] => Array
            (
                [playerStatSummaryType] => AramUnranked5x5
                [wins] => 2
                [losses] => 0
                [modifyDate] => 1389254885000
                [aggregatedStats] => Array
                    (
                        [totalChampionKills] => 38
                        [totalTurretsKilled] => 2
                        [totalAssists] => 77
                    )

            )

        [1] => Array
            (
                [playerStatSummaryType] => OdinUnranked
                [wins] => 0
                [losses] => 0
                [modifyDate] => 1376980500000
                [aggregatedStats] => Array
                    (
                    )

            )

        [2] => Array
            (
                [playerStatSummaryType] => OneForAll5x5
                [wins] => 0
                [losses] => 0
                [modifyDate] => 1388558434000
                [aggregatedStats] => Array
                    (
                    )

            )

        [3] => Array
            (
                [playerStatSummaryType] => Unranked
                [wins] => 141
                [losses] => 0
                [modifyDate] => 1389338360000
                [aggregatedStats] => Array
                    (
                        [totalChampionKills] => 1114
                        [totalMinionKills] => 36216
                        [totalTurretsKilled] => 287
                        [totalNeutralMinionsKilled] => 2265
                        [totalAssists] => 1923
                    )

            )

That thing I want to do here, is get the [playerStatSummaryType] => Unranked, but how am i able to do this, when in the first example it located at[0], in the second in [3] and so on.

Cause if I took the [0] everytime, it would come with wrong stats

Hope someone can help me out :)

Upvotes: 0

Views: 67

Answers (2)

Rolf
Rolf

Reputation: 5743

Maybe a foreach loop, or maybe array_map() with a recursive function... You might want to consider using a database (SQL or object-based). Multidimentional arrays are not great for searching and stuff like that.

Upvotes: 0

Muhammad Saud
Muhammad Saud

Reputation: 354

you mean it will always be on the last index?

Upvotes: 1

Related Questions