3v4l.org

run code in 500+ 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($myArray); iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); function traverseRecursiveArray($iterator) { 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/qSrZ8
function name:  (null)
number of ops:  15
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                                                     
   49    11        INIT_FCALL                                                   'var_dump'
         12        SEND_VAR                                                     !0
         13        DO_ICALL                                                     
         14      > RETURN                                                       1

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

End of function manipulate

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.64 ms | 3600 KiB | 15 Q