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); foreach ($tree as $cid => $item) { var_dump($item); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/muEHc
function name:  (null)
number of ops:  12
compiled vars:  !0 = $tree, !1 = $item, !2 = $cid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'build'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   38     3      > FE_RESET_R                                       $5      !0, ->10
          4    > > FE_FETCH_R                                       ~6      $5, !1, ->10
          5    >   ASSIGN                                                   !2, ~6
   39     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   38     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $5
   40    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/muEHc
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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.72 ms | 1403 KiB | 16 Q