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[ $treeByCat[ $id ] ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ]), $gTree); 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/m3pd3
function name:  (null)
number of ops:  11
compiled vars:  !0 = $treeByParent, !1 = $treeByCat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, <array>
   33     1        ASSIGN                                                   !1, <array>
   44     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 = 13, Position 2 = 25
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/m3pd3
function name:  getTree
number of ops:  27
compiled vars:  !0 = $treeByParent, !1 = $treeByCat, !2 = $id, !3 = $listed, !4 = $gTree
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                                      ~7      !1, !2
          6        ASSIGN_DIM                                               !4
          7        OP_DATA                                                  ~7
   17     8        FETCH_DIM_R                                      ~8      !1, !2
          9        FETCH_DIM_R                                      ~9      !0, ~8
         10        COUNT                                            ~10     ~9
         11        IS_SMALLER                                               0, ~10
         12      > JMPZ                                                     ~11, ->25
         13    >   INIT_FCALL                                               'array_merge'
         14        INIT_FCALL_BY_NAME                                       'getTree'
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !1
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $12     !1, !2
         19        SEND_FUNC_ARG                                            $12
         20        DO_FCALL                                      0  $13     
         21        SEND_VAR                                                 $13
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !4, $14
   19    25    > > RETURN                                                   !4
   21    26*     > RETURN                                                   null

End of function gettree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.79 ms | 1399 KiB | 18 Q