3v4l.org

run code in 300+ PHP versions simultaneously
<?php function build(){ $items = [ 1=>['categories_id'=>1,'name'=>'父1','parent_id'=>0], 9=>['categories_id'=>9,'name'=>'儿3-1','parent_id'=>3], 15=>['categories_id'=>15,'name'=>'儿3-1-1','parent_id'=>14], 3=>['categories_id'=>3,'name'=>'父3','parent_id'=>0], 4=>['categories_id'=>4,'name'=>'儿1-1','parent_id'=>1], 6=>['categories_id'=>6,'name'=>'儿1-3','parent_id'=>1], 12=>['categories_id'=>12,'name'=>'儿2-1-1','parent_id'=>7], 2=>['categories_id'=>2,'name'=>'父2','parent_id'=>0], 5=>['categories_id'=>5,'name'=>'儿1-2','parent_id'=>1], 8=>['categories_id'=>8,'name'=>'儿2-1','parent_id'=>2], 11=>['categories_id'=>11,'name'=>'儿1-1-1','parent_id'=>4], 7=>['categories_id'=>7,'name'=>'儿2-1','parent_id'=>2], 10=>['categories_id'=>10,'name'=>'儿3-1-1','parent_id'=>9], 13=>['categories_id'=>13,'name'=>'儿3-1-1','parent_id'=>10], 14=>['categories_id'=>14,'name'=>'儿3-1-1','parent_id'=>13], 16=>['categories_id'=>16,'name'=>'儿3-1-1','parent_id'=>10], ]; $tree = array(); foreach($items as $cid => $item){ if(isset($items[$item['parent_id']])){ // var_dump($tree); $items[$item['parent_id']]['childs'][$cid] = &$items[$cid]; }else{ $tree[$cid] = &$items[$cid]; } } return $tree; } $tree = build(); print_r($tree); function get($tree, $level) { // static $tree; $lv = 1; $res = array(); foreach ($tree as $cid => $item) { /*if ($item['parent_id'] == 0) { if ($lv == $level) { continue; } $res[$cid] = $item; $lv ++; }*/ // var_dump($item); if ($item['parent_id'] == 0) { $lv = 1; } if (is_array($item)) { $lv ++; return get($item, $level); } var_dump($lv); } } $get = get($tree, 2); // var_dump($get);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VKJ7C
function name:  (null)
number of ops:  12
compiled vars:  !0 = $tree, !1 = $get
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'build'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   36     3        INIT_FCALL                                               'print_r'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   64     6        INIT_FCALL                                               'get'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 2
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
   66    11      > RETURN                                                   1

Function build:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/VKJ7C
function name:  build
number of ops:  24
compiled vars:  !0 = $items, !1 = $tree, !2 = $item, !3 = $cid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   23     1        ASSIGN                                                   !1, <array>
   24     2      > FE_RESET_R                                       $6      !0, ->21
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->21
          4    >   ASSIGN                                                   !3, ~7
   25     5        FETCH_DIM_R                                      ~9      !2, 'parent_id'
          6        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~9
          7      > JMPZ                                                     ~10, ->16
   27     8    >   FETCH_DIM_R                                      ~11     !2, 'parent_id'
          9        FETCH_DIM_W                                      $15     !0, !3
         10        MAKE_REF                                         $16     $15
         11        FETCH_DIM_W                                      $12     !0, ~11
         12        FETCH_DIM_W                                      $13     $12, 'childs'
         13        FETCH_DIM_W                                      $14     $13, !3
         14        ASSIGN_REF                                               $14, $16
         15      > JMP                                                      ->20
   29    16    >   FETCH_DIM_W                                      $19     !0, !3
         17        MAKE_REF                                         $20     $19
         18        FETCH_DIM_W                                      $18     !1, !3
         19        ASSIGN_REF                                               $18, $20
   24    20    > > JMP                                                      ->3
         21    >   FE_FREE                                                  $6
   33    22      > RETURN                                                   !1
   34    23*     > RETURN                                                   null

End of function build

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 11
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/VKJ7C
function name:  get
number of ops:  26
compiled vars:  !0 = $tree, !1 = $level, !2 = $lv, !3 = $res, !4 = $item, !5 = $cid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        ASSIGN                                                   !2, 1
   42     3        ASSIGN                                                   !3, <array>
   43     4      > FE_RESET_R                                       $8      !0, ->24
          5    > > FE_FETCH_R                                       ~9      $8, !4, ->24
          6    >   ASSIGN                                                   !5, ~9
   53     7        FETCH_DIM_R                                      ~11     !4, 'parent_id'
          8        IS_EQUAL                                                 ~11, 0
          9      > JMPZ                                                     ~12, ->11
   54    10    >   ASSIGN                                                   !2, 1
   56    11    >   TYPE_CHECK                                  128          !4
         12      > JMPZ                                                     ~14, ->20
   57    13    >   PRE_INC                                                  !2
   58    14        INIT_FCALL_BY_NAME                                       'get'
         15        SEND_VAR_EX                                              !4
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $16     
         18        FE_FREE                                                  $8
         19      > RETURN                                                   $16
   60    20    >   INIT_FCALL                                               'var_dump'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                                 
   43    23      > JMP                                                      ->5
         24    >   FE_FREE                                                  $8
   62    25      > RETURN                                                   null

End of function get

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
208.56 ms | 1402 KiB | 19 Q