Ekumahost Ekumahost - 1 year ago 49
JSON Question

How to loop through JSON object values in PHP?

I have a JSON Object and I want to loop through the values:

$json = '{"1":a,"2":b,"3":c,"4":d,"5":e}';
$obj = json_decode($json, TRUE);
for($i=0; $i<count($obj['a']); $i++) {
echo $i;

I want the
to display the
that are the values in the object.

Answer Source

Try using.

$json = '{"1":"a","2":"b","3":"c","4":"d","5":"e"}';
 $obj = json_decode($json, TRUE);

foreach($obj as $key => $value) 
echo 'Your key is: '.$key.' and the value of the key is:'.$value;

p.s not tested ;-)