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 $i to display the abcde that are the values in the object.
print_r($obj)$i<count($obj['a'])should be$i<count($obj). You want to count the total elements in the array, not the elements in the first value, which is 0 in this case. Alternativelyforeachis more readable.{"1": "a", ... etc}.