3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $listed = []) { $gTree = []; $gTree[] = $treeByCat[ $id ]; if ( count($treeByParent[ $id ]) > 0) { foreach ($treeByParent[ $id ] as $cat) $gTree[] = $cat; } if ( count($treeByParent[$id]) > 0 ) getTree($treeByParent, $treeByCat, $treeByCat[ $id ]); return $gTree; } $treeByParent = array( 0 => array(1, 2), 1 => array(3, 7), 3 => array(4), 4 => array(5) ); $treeByCat = array( 1 => 0, 2 => 0, 3 => 1, 7 => 1, 4 => 3, 5 => 4 ); print_r( getTree($treeByParent, $treeByCat, 4) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dbZ8m
function name:  (null)
number of ops:  11
compiled vars:  !0 = $treeByParent, !1 = $treeByCat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   31     1        ASSIGN                                                   !1, <array>
   42     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'gettree'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 4
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function gettree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 18
Branch analysis from position: 19
filename:       /in/dbZ8m
function name:  getTree
number of ops:  32
compiled vars:  !0 = $treeByParent, !1 = $treeByCat, !2 = $id, !3 = $listed, !4 = $gTree, !5 = $cat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      <array>
    5     4        ASSIGN                                                   !4, <array>
    7     5        FETCH_DIM_R                                      ~8      !1, !2
          6        ASSIGN_DIM                                               !4
          7        OP_DATA                                                  ~8
    9     8        FETCH_DIM_R                                      ~9      !0, !2
          9        COUNT                                            ~10     ~9
         10        IS_SMALLER                                               0, ~10
         11      > JMPZ                                                     ~11, ->19
   11    12    >   FETCH_DIM_R                                      ~12     !0, !2
         13      > FE_RESET_R                                       $13     ~12, ->18
         14    > > FE_FETCH_R                                               $13, !5, ->18
         15    >   ASSIGN_DIM                                               !4
         16        OP_DATA                                                  !5
         17      > JMP                                                      ->14
         18    >   FE_FREE                                                  $13
   15    19    >   FETCH_DIM_R                                      ~15     !0, !2
         20        COUNT                                            ~16     ~15
         21        IS_SMALLER                                               0, ~16
         22      > JMPZ                                                     ~17, ->30
         23    >   INIT_FCALL_BY_NAME                                       'getTree'
         24        SEND_VAR_EX                                              !0
         25        SEND_VAR_EX                                              !1
         26        CHECK_FUNC_ARG                                           
         27        FETCH_DIM_FUNC_ARG                               $18     !1, !2
         28        SEND_FUNC_ARG                                            $18
         29        DO_FCALL                                      0          
   17    30    > > RETURN                                                   !4
   19    31*     > RETURN                                                   null

End of function gettree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.25 ms | 1394 KiB | 16 Q