3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $listed = []) { $gTree = []; $gTree[] = $id; if ( count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ]), $gTree); if ( count($treeByParent[ $id ]) > 0 ) { foreach ($treeByParent[ $id ] as $cat) $gTree = array_merge( getTree($treeByParent, $treeByCat, $cat), $gTree); } return $gTree; } $treeByParent = array( 0 => array(1, 2), 1 => array(3, 7), 3 => array(4), 4 => array(5), 5 => array(6, 8) ); $treeByCat = array( 1 => 0, 2 => 0, 3 => 1, 7 => 1, 4 => 3, 5 => 4, 6 => 5, 8 => 5 ); print_r( getTree($treeByParent, $treeByCat, 4) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/re9IK
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>
   32     1        ASSIGN                                                   !1, <array>
   45     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 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 42
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 41
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 41
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 42
Branch analysis from position: 23
filename:       /in/re9IK
function name:  getTree
number of ops:  44
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        ASSIGN_DIM                                               !4
          6        OP_DATA                                                  !2
    9     7        FETCH_DIM_R                                      ~8      !1, !2
          8        COUNT                                            ~9      ~8
          9        IS_SMALLER                                               0, ~9
         10      > JMPZ                                                     ~10, ->23
         11    >   INIT_FCALL                                               'array_merge'
         12        INIT_FCALL_BY_NAME                                       'getTree'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAR_EX                                              !1
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $11     !1, !2
         17        SEND_FUNC_ARG                                            $11
         18        DO_FCALL                                      0  $12     
         19        SEND_VAR                                                 $12
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                         $13     
         22        ASSIGN                                                   !4, $13
   11    23    >   FETCH_DIM_R                                      ~15     !0, !2
         24        COUNT                                            ~16     ~15
         25        IS_SMALLER                                               0, ~16
         26      > JMPZ                                                     ~17, ->42
   13    27    >   FETCH_DIM_R                                      ~18     !0, !2
         28      > FE_RESET_R                                       $19     ~18, ->41
         29    > > FE_FETCH_R                                               $19, !5, ->41
         30    >   INIT_FCALL                                               'array_merge'
         31        INIT_FCALL_BY_NAME                                       'getTree'
         32        SEND_VAR_EX                                              !0
         33        SEND_VAR_EX                                              !1
         34        SEND_VAR_EX                                              !5
         35        DO_FCALL                                      0  $20     
         36        SEND_VAR                                                 $20
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                         $21     
         39        ASSIGN                                                   !4, $21
         40      > JMP                                                      ->29
         41    >   FE_FREE                                                  $19
   17    42    > > RETURN                                                   !4
   19    43*     > RETURN                                                   null

End of function gettree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.57 ms | 1407 KiB | 18 Q