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($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/ndGAI
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 = 15, Position 2 = 27
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/ndGAI
function name:  getTree
number of ops:  29
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
    8     7        FETCH_DIM_R                                      ~8      !1, !2
          8        ASSIGN_DIM                                               !4
          9        OP_DATA                                                  ~8
   18    10        FETCH_DIM_R                                      ~9      !1, !2
         11        FETCH_DIM_R                                      ~10     !0, ~9
         12        COUNT                                            ~11     ~10
         13        IS_SMALLER                                               0, ~11
         14      > JMPZ                                                     ~12, ->27
         15    >   INIT_FCALL                                               'array_merge'
         16        INIT_FCALL_BY_NAME                                       'getTree'
         17        SEND_VAR_EX                                              !0
         18        SEND_VAR_EX                                              !1
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $13     !1, !2
         21        SEND_FUNC_ARG                                            $13
         22        DO_FCALL                                      0  $14     
         23        SEND_VAR                                                 $14
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $15     
         26        ASSIGN                                                   !4, $15
   20    27    > > RETURN                                                   !4
   22    28*     > RETURN                                                   null

End of function gettree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.66 ms | 1403 KiB | 18 Q