3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array( "a", array( "a", "b", array( "a", "b", "c", array( "a", "b", "c", "d", array("the end") ) ) ) ); $recursive_array_iterator = new RecursiveArrayIterator(new ArrayObject($myArray)); iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); var_dump($recursive_array_iterator); function traverseRecursiveArray($iterator) { $i = 0; while ($iterator->valid()) { if ($iterator->hasChildren()) { traverseRecursiveArray($iterator->getChildren()); } else { $iterator->offsetSet($iterator->key(), manipulate($iterator->current())); echo $iterator->key() . ' => ' . $iterator->current() . PHP_EOL; } $iterator->next(); } } function manipulate($string) { $string .= " appended"; return $string; } var_dump($myArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C0ntD
function name:  (null)
number of ops:  21
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        NEW                                              $4      'ArrayObject'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $4
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $3
   24     8        INIT_FCALL                                               'iterator_apply'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 'traverseRecursiveArray'
         11        INIT_ARRAY                                       ~8      !1
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                                 
   26    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
   53    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

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

End of function traverserecursivearray

Function manipulate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C0ntD
function name:  manipulate
number of ops:  4
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        ASSIGN_OP                                     8          !0, '+appended'
   50     2      > RETURN                                                   !0
   51     3*     > RETURN                                                   null

End of function manipulate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.12 ms | 1400 KiB | 17 Q