Posted By

sidisinsane on 12/02/08


Tagged

php array recursive multi-dimensional


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

robe
technopoetic


Recursively traverse a Multi-dimensional Array


 / Published in: PHP
 

  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
Posted By: robe on December 5, 2008

Title should be Recursively

Posted By: sidisinsane on December 6, 2008

Thanks for catching that. Changed it.

You need to login to post a comment.