php displaying API (rest) info in a for each loop -
well have been displaying api stats riot games...however 1 weird. , cannot life of me results entries, leaguepoints, wins, isfreshblood. stuff that
this info scraping from.
{"29283170": [ { "queue": "ranked_solo_5x5", "name": "annie's blades", "entries": [{ "leaguepoints": 52, "isfreshblood": false, "ishotstreak": false, "division": "ii", "isinactive": false, "isveteran": false, "playerorteamname": "cleland", "playerorteamid": "29283170", "wins": 5 }], "tier": "bronze" }, { "queue": "ranked_team_3x3", "name": "blitzcrank's avengers", "tier": "challenger" } ]} i can tier, no problem. have tried many different methods below few have tried sigh (this each loop)
attempt #1
$objs = json_decode($response3, true); foreach ($objs['entries'] $val) { $league=$val['tier']; $pts=$val['leaguepoints']; $wins=$val['wins']; } attempt #2 *note $myid league of legends player id a.k.a
{"29283170": [ so fun. doable below.
$objs = json_decode($response3, true); foreach ($objs[$myid] $val) { $league=$val['tier']; $pts=$val['entries']['leaguepoints']; $wins=$val['entries']['wins']; } now above can tier, outside entries block. cannot access info leaguepoints or wins. have been trying few days now, help..would much appreciated.
you can access array elements, json_decode(), true lastly parameter , associative array returned, can to:
$myid = "29283170"; foreach ($objs[$myid] $val) { $league=$val['tier']; if(array_key_exists('entries', $val)) { echo $val['entries'][0]['leaguepoints']; echo "<br />"; echo $val['entries'][0]['wins']; } } php api rest
No comments:
Post a Comment