You can use [RecursiveArrayIterator][1] to iterate a multidimensional array
[1]: http://us2.php.net/manual/en/recursivearrayiterator.getchildren.php
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
echo "$key:\n";
} else {
echo "$key => $val\n";
}
}
The output :
John:
status => Wait
Jennifer:
status => Active
James:
status => Active
age => 56
count => 10
progress => 0.0029857
bad => 0
To iterate over a multidimensional array, you can use [RecursiveArrayIterator][1]
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
echo nl2br("$key:\n");
} else {
echo nl2br("$key => $val\n");
}
}
Output:
John:
status => Wait
Jennifer:
status => Active
James:
status => Active
age => 56
count => 10
progress => 0.0029857
bad => 0
[run on codepad][2]
[1]: http://us2.php.net/manual/en/recursivearrayiterator.getchildren.php
[2]: http://codepad.org/Gtk8DqJE