3v4l.org

run code in 500+ PHP versions simultaneously
<?php $example = [ ['text' => 'a', 'children' => [ ['text' => 'b'], ['text' => 'c'], ['text' => 'd', 'children' => [ ['text' => 'e'], ['text' => 'f'], ['text' => 'g', 'children' => [ ['text' => 'h'], ['text' => 'i'], ['text' => 'j'], ]], ['text' => 'k'], ['text' => 'l'], ['text' => 'm'], ]], ['text' => 'n'], ['text' => 'o'], ['text' => 'p'], ]] ]; function listElements(array $input, $depth = 0) { end($input); $final = key($input); $n = count($input); foreach ($input as $key => $element) { echo $element['text']; echo ($key == $final) ? " last of $n," : ''; echo " depth $depth", PHP_EOL; if (isset($element['children'])) { listElements($element['children'], $depth + 1); } } } listElements($example);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J9fek
function name:  (null)
number of ops:  5
compiled vars:  !0 = $example
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   40     1        INIT_FCALL                                                   'listelements'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0          
          4      > RETURN                                                       1

Function listelements:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 39
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 39
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 38
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 38
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 38
Branch analysis from position: 31
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/J9fek
function name:  listElements
number of ops:  41
compiled vars:  !0 = $input, !1 = $depth, !2 = $final, !3 = $n, !4 = $element, !5 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      0
   27     2        INIT_FCALL                                                   'end'
          3        SEND_REF                                                     !0
          4        DO_ICALL                                                     
   28     5        INIT_FCALL                                                   'key'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $7      
          8        ASSIGN                                                       !2, $7
   29     9        COUNT                                                ~9      !0
         10        ASSIGN                                                       !3, ~9
   30    11      > FE_RESET_R                                           $11     !0, ->39
         12    > > FE_FETCH_R                                           ~12     $11, !4, ->39
         13    >   ASSIGN                                                       !5, ~12
   31    14        FETCH_DIM_R                                          ~14     !4, 'text'
         15        ECHO                                                         ~14
   32    16        IS_EQUAL                                                     !5, !2
         17      > JMPZ                                                         ~15, ->23
         18    >   ROPE_INIT                                         3  ~17     '+last+of+'
         19        ROPE_ADD                                          1  ~17     ~17, !3
         20        ROPE_END                                          2  ~16     ~17, '%2C'
         21        QM_ASSIGN                                            ~19     ~16
         22      > JMP                                                          ->24
         23    >   QM_ASSIGN                                            ~19     ''
         24    >   ECHO                                                         ~19
   33    25        NOP                                                          
         26        FAST_CONCAT                                          ~20     '+depth+', !1
         27        ECHO                                                         ~20
         28        ECHO                                                         '%0A'
   34    29        ISSET_ISEMPTY_DIM_OBJ                             0          !4, 'children'
         30      > JMPZ                                                         ~21, ->38
   35    31    >   INIT_FCALL_BY_NAME                                           'listElements'
         32        CHECK_FUNC_ARG                                               
         33        FETCH_DIM_FUNC_ARG                                   $22     !4, 'children'
         34        SEND_FUNC_ARG                                                $22
         35        ADD                                                  ~23     !1, 1
         36        SEND_VAL_EX                                                  ~23
         37        DO_FCALL                                          0          
   30    38    > > JMP                                                          ->12
         39    >   FE_FREE                                                      $11
   38    40      > RETURN                                                       null

End of function listelements

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
233.58 ms | 2147 KiB | 16 Q