CopyPastor

Detecting plagiarism made easy.

Score: 0.8000577092170715; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-04-21
by Umer Hayat

Original Post

Original - Posted on 2010-12-03
by Gordon



            
Present in both answers; Present only in the new answer; Present only in the old answer;

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

        
Present in both answers; Present only in the new answer; Present only in the old answer;