BigJobbies BigJobbies - 1 year ago 70
JSON Question

PHP looping over json objects in my database

Im storing some values using the mysql json field type, in Sequel Pro im seeing them as follows


In my PHP file, i can print out the contents using

echo $plan->features;

but what i want to do is look over each one so i can style them, but the problem is when i stick it in a foreach loop i get the following:

Invalid argument supplied for foreach()

My loop is straight forward

foreach ($plan->features as $features) {

Im not sure im doing things right.

Any help would be greatly appreciated.


Answer Source

This is a JSON String


User json_decode() for the above string

$string = json_decode($teststring,TRUE);

And after that you can for loop the variable or foreach the variable

foreach($string as $single_value)
     echo $single_value.'<br>';





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download