hyster Posted May 20, 2013 Share Posted May 20, 2013 I have a feed which is in a json format. part of the script needs to be looped. ive worked out (I think) that I need to use foreach to split the data but I cannot find an example that works. this is similar to what I have tried so far. $phpArray = json_decode($test); //print_r($phpArray); foreach ($phpArray as $key => {'data'}->{'vehicles'}->{'name'}->) { echo "<p>$key | $value</p></br>"; } each iteration holds this data {'data'}->{'vehicles'}-> spotted localized_name name level damageDealt survivedBattles battle_count nation" image_url frags win_count class the data that is fixed ie players name I can pull ok but not the data that's needs looping. pointers gratefully accepted Link to comment https://forums.phpfreaks.com/topic/278211-json-split-array/ Share on other sites More sharing options...
Eiseth Posted May 20, 2013 Share Posted May 20, 2013 Use http://jsoneditoronline.org/ to format your json to a readable file Then look for a element that "[numbers]" beside it (e.g. in twitter json it is results[20]), usually that is where you gonna loop Try this, but I'm not sure though because I don't know the structure of your JSON $phpArray = json_decode($test); foreach ($phpArray->vehicles as $item) { // do what you want echo $item->spotted . '<br>'; echo $item->localized_name . '<br>'; } Link to comment https://forums.phpfreaks.com/topic/278211-json-split-array/#findComment-1431209 Share on other sites More sharing options...
hyster Posted May 20, 2013 Author Share Posted May 20, 2013 thx eiseth that got me sorted Link to comment https://forums.phpfreaks.com/topic/278211-json-split-array/#findComment-1431233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.