3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $listed = []) { $gTree = []; $gTree[] = $id; //$gTree[] = $treeByCat[ $id ]; /** if ( count($treeByParent[ $id ]) > 0) { foreach ($treeByParent[ $id ] as $cat) $gTree[] = $cat; } */ if ( count($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/YY6UJ
function name:  (null)
number of ops:  11
compiled vars:  !0 = $treeByParent, !1 = $treeByCat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   34     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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/YY6UJ
function name:  getTree
number of ops:  25
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        ASSIGN_DIM                                               !4
          6        OP_DATA                                                  !2
   18     7        FETCH_DIM_R                                      ~7      !1, !2
          8        COUNT                                            ~8      ~7
          9        IS_SMALLER                                               0, ~8
         10      > JMPZ                                                     ~9, ->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                               $10     !1, !2
         17        SEND_FUNC_ARG                                            $10
         18        DO_FCALL                                      0  $11     
         19        SEND_VAR                                                 $11
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !4, $12
   20    23    > > RETURN                                                   !4
   22    24*     > RETURN                                                   null

End of function gettree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.77 ms | 1399 KiB | 18 Q