0

The data comes from here.

I want to print the wins from "playerStatSummaryType": "RankedSolo5x5" so how can I get the data from RankedSolo5x5?

This is my code:

$claw = "https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/43216818/summary?season=SEASON4&api_key=010ba2bc-2c40-4b98-873e-b1d148c9e379";
$z0r = file_get_contents($claw);
$gaza = json_decode($z0r, true);
$wins = $gaza['playerStatSummaries'][4]['wins'];
print $wins;
2
  • Please show what you have tried so far to get it to print, and explain a bit more how you want it to be presented. At this stage I would recommend you Google json to PHP. At least show some level of attempt or you won't get an answer Commented Jul 12, 2014 at 16:50
  • I blame temporary blindness? You are correct, my question made no sense! Commented Jul 12, 2014 at 18:58

2 Answers 2

1
$wins = $gaza['playerStatSummaries'][4];
echo $key = array_search('RankedSolo5x5', $wins);

It will return you its type name

Sign up to request clarification or add additional context in comments.

Comments

0

Try it this way. Since the JSON data format is odd, rolling through the returned 'playerStatSummaries' array and acting on the 'playerStatSummaryType' that equals 'RankedSolo5x5' seems like the best future-proof solution:

$claw = "https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/43216818/summary?season=SEASON4&api_key=010ba2bc-2c40-4b98-873e-b1d148c9e379";
$z0r = file_get_contents($claw);
$gaza = json_decode($z0r, true);

// Roll through the 'playerStatSummaries' array & act on the 'playerStatSummaryType' that equals 'RankedSolo5x5'.
$wins = '';
foreach ($gaza['playerStatSummaries'] as $key => $value) {
  if ($value['playerStatSummaryType'] == 'RankedSolo5x5') {
    $wins = $value['wins'];
  }
}

// Return the value of `$wins`.
echo $wins;

// Check the output of `$gaza` for debugging.
echo '<pre>';
print_r($gaza);
echo '</pre>';

I also added the print_r($gaza); so you can actually see what data is being returned from the call. Visualizing the output is the best way to debug a process like this.

The structure of the array is shown to be something like this:

Array
(
    [summonerId] => 43216818
    [playerStatSummaries] => Array
        (
            [0] => Array
                (
                    [playerStatSummaryType] => AramUnranked5x5
                    [wins] => 41
                    [modifyDate] => 1405178930000
                    [aggregatedStats] => Array
                        (
                            [totalChampionKills] => 632
                            [totalTurretsKilled] => 26
                            [totalAssists] => 1491
                        )

                )

And the data point you are looking to act on is this:

[5] => Array
    (
        [playerStatSummaryType] => RankedTeam3x3
        [wins] => 4
        [losses] => 1
        [modifyDate] => 1381833912000
        [aggregatedStats] => Array
            (
                [totalChampionKills] => 33
                [totalMinionKills] => 319
                [totalTurretsKilled] => 6
                [totalNeutralMinionsKilled] => 33
                [totalAssists] => 44
            )

    )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.