3v4l.org

run code in 500+ PHP versions simultaneously
<?php $list = array( array('id' => 3, 'name' => 'Phones', 'parent_id' => 0,), array('id' => 256, 'name' => 'Accessories', 'parent_id' => 0,), array('id' => 308, 'name' => 'Appliances', 'parent_id' => 0,), array('id' => 1057, 'name' => 'Smart', 'parent_id' => 0,), array('id' => 1065, 'name' => 'Smart Phones', 'parent_id' => 3,), array('id' => 1066, 'name' => 'Feature Phones', 'parent_id' => 3,), array('id' => 1069, 'name' => 'Samsung', 'parent_id' => 1065,), array('id' => 1070, 'name' => 'Apple', 'parent_id' => 1065,), array('id' => 1072, 'name' => 'Apple', 'parent_id' => 1066,), array('id' => 1075, 'name' => 'Tablets', 'parent_id' => 0,), array('id' => 1076, 'name' => 'Samsung', 'parent_id' => 1066,), array('id' => 1077, 'name' => 'All Brands', 'parent_id' => 1075,), array('id' => 1078, 'name' => 'Samsung', 'parent_id' => 1077,), array('id' => 1079, 'name' => 'Protector', 'parent_id' => 256,), array('id' => 1080, 'name' => 'Power', 'parent_id' => 256,), array('id' => 1081, 'name' => 'Cable', 'parent_id' => 256,), array('id' => 1082, 'name' => 'Memory', 'parent_id' => 256,), ); function quote_make_tree($list, $deep = 1, $root = 0) { $tree = $packData = []; foreach ($list as $row) { $packData[$row['id']] = $row; } foreach ($packData as $key => $val) { if ($val['parent_id'] == $root) { $tree[] = &$packData[$key]; } else { $packData[$val['parent_id']]['children'][] = &$packData[$key]; } } return $tree; } $tree = quote_make_tree($list); print_r($tree);

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cYU7h
function name:  (null)
number of ops:  9
compiled vars:  !0 = $list, !1 = $tree
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                       !0, <array>
   44     1        INIT_FCALL                                                   'quote_make_tree'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $3      
          4        ASSIGN                                                       !1, $3
   47     5        INIT_FCALL                                                   'print_r'
          6        SEND_VAR                                                     !1
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Function quote_make_tree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 31
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 31
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 11
filename:       /in/cYU7h
function name:  quote_make_tree
number of ops:  34
compiled vars:  !0 = $list, !1 = $deep, !2 = $root, !3 = $tree, !4 = $packData, !5 = $row, !6 = $val, !7 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      1
          2        RECV_INIT                                            !2      0
   26     3        ASSIGN                                               ~8      !4, <array>
          4        ASSIGN                                                       !3, ~8
   27     5      > FE_RESET_R                                           $10     !0, ->11
          6    > > FE_FETCH_R                                                   $10, !5, ->11
   28     7    >   FETCH_DIM_R                                          ~11     !5, 'id'
          8        ASSIGN_DIM                                                   !4, ~11
          9        OP_DATA                                                      !5
   27    10      > JMP                                                          ->6
         11    >   FE_FREE                                                      $10
   31    12      > FE_RESET_R                                           $13     !4, ->31
         13    > > FE_FETCH_R                                           ~14     $13, !6, ->31
         14    >   ASSIGN                                                       !7, ~14
   33    15        FETCH_DIM_R                                          ~16     !6, 'parent_id'
         16        IS_EQUAL                                                     !2, ~16
         17      > JMPZ                                                         ~17, ->23
   34    18    >   FETCH_DIM_W                                          $19     !4, !7
         19        MAKE_REF                                             $20     $19
         20        FETCH_DIM_W                                          $18     !3
         21        ASSIGN_REF                                                   $18, $20
   33    22      > JMP                                                          ->30
   36    23    >   FETCH_DIM_R                                          ~22     !6, 'parent_id'
         24        FETCH_DIM_W                                          $26     !4, !7
         25        MAKE_REF                                             $27     $26
         26        FETCH_DIM_W                                          $23     !4, ~22
         27        FETCH_DIM_W                                          $24     $23, 'children'
         28        FETCH_DIM_W                                          $25     $24
         29        ASSIGN_REF                                                   $25, $27
   31    30    > > JMP                                                          ->13
         31    >   FE_FREE                                                      $13
   41    32      > RETURN                                                       !3
   42    33*     > RETURN                                                       null

End of function quote_make_tree

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
129.12 ms | 485 KiB | 9 Q