3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 1=>['id'=>1,'name'=>'父1','father'=>NULL], 2=>['id'=>2,'name'=>'父2','father'=>NULL], 3=>['id'=>3,'name'=>'父3','father'=>NULL], 4=>['id'=>4,'name'=>'儿1-1','father'=>1], 5=>['id'=>5,'name'=>'儿1-2','father'=>1], 6=>['id'=>6,'name'=>'儿1-3','father'=>1], 7=>['id'=>7,'name'=>'儿2-1','father'=>2], 8=>['id'=>8,'name'=>'儿2-1','father'=>2], 9=>['id'=>9,'name'=>'儿3-1','father'=>3], 10=>['id'=>10,'name'=>'儿3-1-1','father'=>9], 11=>['id'=>11,'name'=>'儿1-1-1','father'=>4], 12=>['id'=>12,'name'=>'儿2-1-1','father'=>7], ]; function generateTree($items){ $tree = array(); foreach($items as $item){ if(isset($items[$item['father']])){ $items[$item['father']]['son'][$item['id']] = &$items[$item['id']]; }else{ $tree[] = &$items[$item['id']]; } } return $tree; } $tree = generateTree($arr); print_r($tree);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BYbU9
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr, !1 = $tree
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   28     1        INIT_FCALL                                               'generatetree'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   29     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

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

End of function generatetree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
282.4 ms | 947 KiB | 18 Q