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; } // $iterator->current = "d"; $iterator->next(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ehJdZ
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                                                 
   43    11      > RETURN                                                   1

Function traverserecursivearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 3
Branch analysis from position: 32
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 = 32, Position 2 = 3
Branch analysis from position: 32
Branch analysis from position: 3
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 3
Branch analysis from position: 32
Branch analysis from position: 3
filename:       /in/ehJdZ
function name:  traverseRecursiveArray
number of ops:  33
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                                                      ->29
   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
   41    27    >   INIT_METHOD_CALL                                         !0, 'next'
         28        DO_FCALL                                      0          
   31    29    >   INIT_METHOD_CALL                                         !0, 'valid'
         30        DO_FCALL                                      0  $15     
         31      > JMPNZ                                                    $15, ->3
   43    32    > > RETURN                                                   null

End of function traverserecursivearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.63 ms | 1400 KiB | 15 Q