Accessing data from JSON in PHP -
this question has answer here:
- how extract data json php? 2 answers
i having difficulty getting data json.
i after doing foreach() json formatted data api, cant work.
here code:
the $player_runes database variable, works totally fine, problem getting data of runeid each array (pages)
foreach($player_runes->pages $statplayerrunesfor){ $statplayerrunesforune0 = $statplayerrunesfor->slots->runeid; echo $statplayerrunesforune0; }
here json data:
{ "29161162": { "summonerid": 29161162, "pages": [ { "id": 24193964, "name": "nida", "current": false, "slots": [ { "runeslotid": 1, "runeid": 5273 }, { "runeslotid": 2, "runeid": 5273 }, { "runeslotid": 3, "runeid": 5273 }, { "runeslotid": 4, "runeid": 5273 }, { "runeslotid": 5, "runeid": 5273 }, { "runeslotid": 6, "runeid": 5273 }, { "runeslotid": 7, "runeid": 5273 }, { "runeslotid": 8, "runeid": 5273 }, { "runeslotid": 9, "runeid": 5273 }, { "runeslotid": 10, "runeid": 5317 }, { "runeslotid": 11, "runeid": 5317 }, { "runeslotid": 12, "runeid": 5317 }, { "runeslotid": 13, "runeid": 5317 }, { "runeslotid": 14, "runeid": 5317 }, { "runeslotid": 15, "runeid": 5317 }, { "runeslotid": 16, "runeid": 5317 }, { "runeslotid": 17, "runeid": 5317 }, { "runeslotid": 18, "runeid": 5317 }, { "runeslotid": 19, "runeid": 5297 }, { "runeslotid": 20, "runeid": 5297 }, { "runeslotid": 21, "runeid": 5297 }, { "runeslotid": 22, "runeid": 5289 }, { "runeslotid": 23, "runeid": 5289 }, { "runeslotid": 24, "runeid": 5289 }, { "runeslotid": 25, "runeid": 5289 }, { "runeslotid": 26, "runeid": 5289 }, { "runeslotid": 27, "runeid": 5289 }, { "runeslotid": 28, "runeid": 5357 }, { "runeslotid": 29, "runeid": 5357 }, { "runeslotid": 30, "runeid": 5357 } ] }, { "id": 24193965, "name": "adc", "current": false, "slots": [ { "runeslotid": 1, "runeid": 5245 }, { "runeslotid": 2, "runeid": 5245 }, { "runeslotid": 3, "runeid": 5245 }, { "runeslotid": 4, "runeid": 5245 }, { "runeslotid": 5, "runeid": 5245 }, { "runeslotid": 6, "runeid": 5245 }, { "runeslotid": 7, "runeid": 5245 }, { "runeslotid": 8, "runeid": 5245 }, { "runeslotid": 9, "runeid": 5245 }, { "runeslotid": 10, "runeid": 5317 }, { "runeslotid": 11, "runeid": 5317 }, { "runeslotid": 12, "runeid": 5317 }, { "runeslotid": 13, "runeid": 5317 }, { "runeslotid": 14, "runeid": 5317 }, { "runeslotid": 15, "runeid": 5317 }, { "runeslotid": 16, "runeid": 5317 }, { "runeslotid": 17, "runeid": 5317 }, { "runeslotid": 18, "runeid": 5317 }, { "runeslotid": 19, "runeid": 5289 }, { "runeslotid": 20, "runeid": 5289 }, { "runeslotid": 21, "runeid": 5289 }, { "runeslotid": 22, "runeid": 5289 }, { "runeslotid": 23, "runeid": 5289 }, { "runeslotid": 24, "runeid": 5289 }, { "runeslotid": 25, "runeid": 5289 }, { "runeslotid": 26, "runeid": 5289 }, { "runeslotid": 27, "runeid": 5289 }, { "runeslotid": 28, "runeid": 5337 }, { "runeslotid": 29, "runeid": 5337 }, { "runeslotid": 30, "runeid": 5337 } ] }, { "id": 60148113, "name": "zed", "current": false, "slots": [ { "runeslotid": 1, "runeid": 5253 }, { "runeslotid": 2, "runeid": 5253 }, { "runeslotid": 3, "runeid": 5253 }, { "runeslotid": 4, "runeid": 5253 }, { "runeslotid": 5, "runeid": 5253 }, { "runeslotid": 6, "runeid": 5253 }, { "runeslotid": 7, "runeid": 5253 }, { "runeslotid": 8, "runeid": 5245 }, { "runeslotid": 9, "runeid": 5245 }, { "runeslotid": 10, "runeid": 5317 }, { "runeslotid": 11, "runeid": 5317 }, { "runeslotid": 12, "runeid": 5317 }, { "runeslotid": 13, "runeid": 5317 }, { "runeslotid": 14, "runeid": 5317 }, { "runeslotid": 15, "runeid": 5317 }, { "runeslotid": 16, "runeid": 5317 }, { "runeslotid": 17, "runeid": 5317 }, { "runeslotid": 18, "runeid": 5317 }, { "runeslotid": 19, "runeid": 5289 }, { "runeslotid": 20, "runeid": 5289 }, { "runeslotid": 21, "runeid": 5289 }, { "runeslotid": 22, "runeid": 5289 }, { "runeslotid": 23, "runeid": 5289 }, { "runeslotid": 24, "runeid": 5289 }, { "runeslotid": 25, "runeid": 5289 }, { "runeslotid": 26, "runeid": 5289 }, { "runeslotid": 27, "runeid": 5289 }, { "runeslotid": 28, "runeid": 5345 }, { "runeslotid": 29, "runeid": 5345 }, { "runeslotid": 30, "runeid": 5335 } ] }, { "id": 60148114, "name": "one", "current": true, "slots": [ { "runeslotid": 1, "runeid": 5253 }, { "runeslotid": 2, "runeid": 5253 }, { "runeslotid": 3, "runeid": 5253 }, { "runeslotid": 4, "runeid": 5253 }, { "runeslotid": 5, "runeid": 5253 }, { "runeslotid": 6, "runeid": 5253 }, { "runeslotid": 7, "runeid": 5253 }, { "runeslotid": 8, "runeid": 5253 }, { "runeslotid": 9, "runeid": 5253 }, { "runeslotid": 10, "runeid": 5317 }, { "runeslotid": 11, "runeid": 5317 }, { "runeslotid": 12, "runeid": 5317 }, { "runeslotid": 13, "runeid": 5317 }, { "runeslotid": 14, "runeid": 5317 }, { "runeslotid": 15, "runeid": 5317 }, { "runeslotid": 16, "runeid": 5317 }, { "runeslotid": 17, "runeid": 5317 }, { "runeslotid": 18, "runeid": 5317 }, { "runeslotid": 19, "runeid": 5289 }, { "runeslotid": 20, "runeid": 5289 }, { "runeslotid": 21, "runeid": 5289 }, { "runeslotid": 22, "runeid": 5289 }, { "runeslotid": 23, "runeid": 5289 }, { "runeslotid": 24, "runeid": 5289 }, { "runeslotid": 25, "runeid": 5289 }, { "runeslotid": 26, "runeid": 5289 }, { "runeslotid": 27, "runeid": 5289 }, { "runeslotid": 28, "runeid": 5335 }, { "runeslotid": 29, "runeid": 5335 }, { "runeslotid": 30, "runeid": 5335 } ] } ] } }
it should work you:
$player_runes = json_decode($variable_with_json, true); foreach($player_runes['pages'] $statplayerrunesfor){ $statplayerrunesforune0 = $statplayerrunesfor['slots']['runeid']; echo $statplayerrunesforune0; }
after decoding become array
not object.
Comments
Post a Comment