Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Dylan Lopez
Added: Mar 5, 2018 9:27 AM
Views: 5
  1. $array = array ("0" => "Value 1"); // Define a complex array tree in this line
  2.  
  3. $iterator = new RecursiveIteratorIterator(
  4.         new RecursiveArrayIterator($array)
  5.     );
  6.  
  7. for($iterator; $iterator->valid(); $iterator->next())
  8.     {
  9.         #echo $iterator->key() ;
  10.       #echo $iterator->current();
  11.       #echo $iterator->getDepth();
  12.            
  13.         printf(
  14.             "Key: %s Value: %s Depth: %s\n",
  15.            $iterator->key(),
  16.             $iterator->current(),
  17.             $iterator->getDepth()
  18.         );
  19.         echo "<br />";
  20.     }