php - Looping over nested arrays below keys -
ok, title might little misleading, i'm not quite sure i'm describing, here goes.
i have following json :
{ "lastmodified": 1368517749000, "name": "requiem paradisum", "realm": "chamber of aspects", "battlegroup": "misery", "level": 25, "side": 1, "achievementpoints": 1710, "emblem": { "icon": 126, "iconcolor": "ffdfa55a", "border": 3, "bordercolor": "ff0f1415", "backgroundcolor": "ff232323" }, "news": [ { "type": "itempurchase", "character": "osmoses", "timestamp": 1368482100000, "itemid": 91781 }, { "type": "itemloot", "character": "greenmean", "timestamp": 1368477900000, "itemid": 87209 }, { "type": "itemloot", "character": "greenmean", "timestamp": 1368475800000, "itemid": 86880 }, { "type": "itempurchase", "character": "osmoses", "timestamp": 1368475380000, "itemid": 91781 }, { "type": "itempurchase", "character": "osmoses", "timestamp": 1368475380000, "itemid": 91779 }, { "type": "itempurchase", "character": "osmoses", "timestamp": 1368475320000, "itemid": 91779 }, { "type": "playerachievement", "character": "osmoses", "timestamp": 1368470700000, "achievement": { "id": 6193, "title": "level 90", "points": 10, "description": "reach level 90.", "rewarditems": [ { "id": 87764, "name": "serpent's heart firework", "icon": "inv_misc_missilelarge_green", "quality": 1, "itemlevel": 1, "tooltipparams": { }, "stats": [ ], "armor": 0 } ], "icon": "achievement_level_90", "criteria": [ ], "accountwide": false, "factionid": 2 } }, basically need loop on in "news" , output it. can't figure out how parse correctly : : without specifying key numbers , b : when gets key contains further keys , further arrays under keys i'm @ loss. (e.g. "player achievement" key) appreciate i'm being bit newbie here , quite possibly on page 1 of "php dummies" swear i've googled death!
see if approach fit. sure json array formatted though.
$test = the_json_array; $array = json_decode($test,true); function recursive($array) { foreach($array $key => $value) { if (!is_array($value)) echo $key.":".$value."<br/>"; else recursive($value); } } recursive($array);
Comments
Post a Comment