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 Quote Link to comment Share on other sites More sharing options...
Solution Eiseth Posted May 20, 2013 Solution 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>'; } Quote Link to comment Share on other sites More sharing options...
hyster Posted May 20, 2013 Author Share Posted May 20, 2013 thx eiseth that got me sorted Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.