Recursively traverse a Multi-dimensional Array


/ Published in: PHP



Copy this code and paste it in your HTML
  1. // Recursively traverses a multi-dimensional array.
  2. function traverseArray($array)
  3. {
  4. // Loops through each element. If element again is array, function is recalled. If not, result is echoed.
  5. foreach($array as $key=>$value)
  6. {
  7. if(is_array($value))
  8. {
  9. traverseArray($value);
  10. }else{
  11. echo $key." = ".$value."<br />\n";
  12. }
  13. }
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.