3v4l.org

run code in 500+ PHP versions simultaneously
<?php $comments = [ [1, 1, 'Comment 1'], [2, 1, 'Comment 2'], [3, 2, 'Comment 3'], [4, 1, 'Comment 4'], [5, 2, 'Comment 5'], [6, 3, 'Comment 6'], [7, 7, 'Comment 7'], ]; $map = []; foreach($comments as $c) { $id = $c[0] === $c[1] ? 0 : $c[1]; $map[$id][] = $c; } function print_comments($arr, $depth) { global $map; foreach($arr as $c) { echo str_repeat("--", $depth) . "{$c[2]}\n"; print_comments($map[$c[0]] ?? [], $depth+1); } } print_comments($map[0], 0);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/CAApZ
function name:  (null)
number of ops:  24
compiled vars:  !0 = $comments, !1 = $map, !2 = $c, !3 = $id
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   13     1        ASSIGN                                                       !1, <array>
   15     2      > FE_RESET_R                                           $6      !0, ->17
          3    > > FE_FETCH_R                                                   $6, !2, ->17
   16     4    >   FETCH_DIM_R                                          ~7      !2, 0
          5        FETCH_DIM_R                                          ~8      !2, 1
          6        IS_IDENTICAL                                                 ~7, ~8
          7      > JMPZ                                                         ~9, ->10
          8    >   QM_ASSIGN                                            ~10     0
          9      > JMP                                                          ->12
         10    >   FETCH_DIM_R                                          ~11     !2, 1
         11        QM_ASSIGN                                            ~10     ~11
         12    >   ASSIGN                                                       !3, ~10
   17    13        FETCH_DIM_W                                          $13     !1, !3
         14        ASSIGN_DIM                                                   $13
         15        OP_DATA                                                      !2
   15    16      > JMP                                                          ->3
         17    >   FE_FREE                                                      $6
   28    18        INIT_FCALL                                                   'print_comments'
         19        FETCH_DIM_R                                          ~15     !1, 0
         20        SEND_VAL                                                     ~15
         21        SEND_VAL                                                     0
         22        DO_FCALL                                          0          
         23      > RETURN                                                       1

Function print_comments:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/CAApZ
function name:  print_comments
number of ops:  26
compiled vars:  !0 = $arr, !1 = $depth, !2 = $map, !3 = $c
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   21     2        BIND_GLOBAL                                                  !2, 'map'
   22     3      > FE_RESET_R                                           $4      !0, ->24
          4    > > FE_FETCH_R                                                   $4, !3, ->24
   23     5    >   INIT_FCALL                                                   'str_repeat'
          6        SEND_VAL                                                     '--'
          7        SEND_VAR                                                     !1
          8        DO_ICALL                                             $5      
          9        FETCH_DIM_R                                          ~6      !3, 2
         10        NOP                                                          
         11        FAST_CONCAT                                          ~7      ~6, '%0A'
         12        CONCAT                                               ~8      $5, ~7
         13        ECHO                                                         ~8
   24    14        INIT_FCALL_BY_NAME                                           'print_comments'
         15        FETCH_DIM_R                                          ~9      !3, 0
         16        FETCH_DIM_IS                                         ~10     !2, ~9
         17        COALESCE                                             ~11     ~10
         18        QM_ASSIGN                                            ~11     <array>
         19        SEND_VAL_EX                                                  ~11
         20        ADD                                                  ~12     !1, 1
         21        SEND_VAL_EX                                                  ~12
         22        DO_FCALL                                          0          
   22    23      > JMP                                                          ->4
         24    >   FE_FREE                                                      $4
   26    25      > RETURN                                                       null

End of function print_comments

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.07 ms | 1785 KiB | 15 Q