boss_iterator_3 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of boss_iterator_3.php

  1. <?php
  2. $tree = array();
  3. $tree[1][2][3] = 'lemon';
  4. $tree[1][4] = 'melon';
  5. $tree[2][3] = 'orange';
  6. $tree[2][5] = 'grape';
  7. $tree[3] = 'pineapple';
  8.  
  9. print_r($tree);
  10.  
  11. $arrayiter = new RecursiveArrayIterator($tree);
  12. $iteriter = new RecursiveIteratorIterator($arrayiter);
  13.  
  14. foreach ($iteriter as $key => $value) {
  15.   $d = $iteriter->getDepth();
  16.   echo "depth=$d k=$key v=$value\n";
  17. }
File Description
  • boss_iterator_3
  • PHP Code
  • 18 Mar-2021
  • 389 Bytes
You can Share it: