3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array( 0, array( 0, 1, array( 0, 1, 2, array( 0, 1, 2, 3, array("the end") ) ) ) ); $recursive_array_iterator = new RecursiveArrayIterator($myArray); iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); function traverseRecursiveArray($iterator) { $i = 0; while ($iterator->valid()) { if ($iterator->hasChildren()) { traverseRecursiveArray($iterator->getChildren()); } else { $iterator->offsetSet($iterator->key(), $i++); echo $iterator->key() . ' => ' . $iterator->current() . PHP_EOL; } echo "!!$i!!" . PHP_EOL; // $iterator->current = "d"; $iterator->next(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8lG7c
function name:  (null)
number of ops:  12
compiled vars:  !0 = $myArray, !1 = $recursive_array_iterator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   23     1        NEW                                              $3      'RecursiveArrayIterator'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   24     5        INIT_FCALL                                               'iterator_apply'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'traverseRecursiveArray'
          8        INIT_ARRAY                                       ~6      !1
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                                 
   45    11      > RETURN                                                   1

Function traverserecursivearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 3
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 3
Branch analysis from position: 37
Branch analysis from position: 3
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 3
Branch analysis from position: 37
Branch analysis from position: 3
filename:       /in/8lG7c
function name:  traverseRecursiveArray
number of ops:  38
compiled vars:  !0 = $iterator, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        ASSIGN                                                   !1, 0
   31     2      > JMP                                                      ->34
   32     3    >   INIT_METHOD_CALL                                         !0, 'hasChildren'
          4        DO_FCALL                                      0  $3      
          5      > JMPZ                                                     $3, ->12
   33     6    >   INIT_FCALL_BY_NAME                                       'traverseRecursiveArray'
          7        INIT_METHOD_CALL                                         !0, 'getChildren'
          8        DO_FCALL                                      0  $4      
          9        SEND_VAR_NO_REF_EX                                       $4
         10        DO_FCALL                                      0          
         11      > JMP                                                      ->27
   35    12    >   INIT_METHOD_CALL                                         !0, 'offsetSet'
         13        INIT_METHOD_CALL                                         !0, 'key'
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR_NO_REF_EX                                       $6
         16        POST_INC                                         ~7      !1
         17        SEND_VAL_EX                                              ~7
         18        DO_FCALL                                      0          
   36    19        INIT_METHOD_CALL                                         !0, 'key'
         20        DO_FCALL                                      0  $9      
         21        CONCAT                                           ~10     $9, '+%3D%3E+'
         22        INIT_METHOD_CALL                                         !0, 'current'
         23        DO_FCALL                                      0  $11     
         24        CONCAT                                           ~12     ~10, $11
         25        CONCAT                                           ~13     ~12, '%0A'
         26        ECHO                                                     ~13
   39    27    >   ROPE_INIT                                     3  ~15     '%21%21'
         28        ROPE_ADD                                      1  ~15     ~15, !1
         29        ROPE_END                                      2  ~14     ~15, '%21%21'
         30        CONCAT                                           ~17     ~14, '%0A'
         31        ECHO                                                     ~17
   43    32        INIT_METHOD_CALL                                         !0, 'next'
         33        DO_FCALL                                      0          
   31    34    >   INIT_METHOD_CALL                                         !0, 'valid'
         35        DO_FCALL                                      0  $19     
         36      > JMPNZ                                                    $19, ->3
   45    37    > > RETURN                                                   null

End of function traverserecursivearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.49 ms | 1400 KiB | 15 Q