3v4l.org

run code in 300+ PHP versions simultaneously
<?php $categories = array( array( 'parent_id' => 0, 'categories_id' => 1, ), array( 'parent_id' => 0, 'categories_id' => 2, ), array( 'parent_id' => 1, 'categories_id' => 11, ), array( 'parent_id' => 1, 'categories_id' => 111, ), array( 'parent_id' => 2, 'categories_id' => 22, ), ); foreach ($categories as $category) { } function build($category, &$tree = array()) { if ($category['parent_id'] == 0) { $category = array( $category['categories_id'] => $category, ); $tree = array_merge($tree, $category); return $tree; } foreach ($tree as $cate_id => $cate) { if ($category['parent_id'] == $cate_id) { $tree[$cate_id]['childs'] = $category; } if (is_array($cate)) { return build($cate, $tree); } } return $tree; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/1KEPR
function name:  (null)
number of ops:  6
compiled vars:  !0 = $categories, !1 = $category
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   26     1      > FE_RESET_R                                       $3      !0, ->4
          2    > > FE_FETCH_R                                               $3, !1, ->4
          3    > > JMP                                                      ->2
          4    >   FE_FREE                                                  $3
   52     5      > RETURN                                                   1

Function build:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 32
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 32
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 23
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/1KEPR
function name:  build
number of ops:  35
compiled vars:  !0 = $category, !1 = $tree, !2 = $cate, !3 = $cate_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   31     2        FETCH_DIM_R                                      ~4      !0, 'parent_id'
          3        IS_EQUAL                                                 ~4, 0
          4      > JMPZ                                                     ~5, ->14
   33     5    >   FETCH_DIM_R                                      ~6      !0, 'categories_id'
          6        INIT_ARRAY                                       ~7      !0, ~6
   32     7        ASSIGN                                                   !0, ~7
   36     8        INIT_FCALL                                               'array_merge'
          9        SEND_VAR                                                 !1
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !1, $9
   38    13      > RETURN                                                   !1
   41    14    > > FE_RESET_R                                       $11     !1, ->32
         15    > > FE_FETCH_R                                       ~12     $11, !2, ->32
         16    >   ASSIGN                                                   !3, ~12
   42    17        FETCH_DIM_R                                      ~14     !0, 'parent_id'
         18        IS_EQUAL                                                 !3, ~14
         19      > JMPZ                                                     ~15, ->23
   43    20    >   FETCH_DIM_W                                      $16     !1, !3
         21        ASSIGN_DIM                                               $16, 'childs'
         22        OP_DATA                                                  !0
   46    23    >   TYPE_CHECK                                  128          !2
         24      > JMPZ                                                     ~18, ->31
   47    25    >   INIT_FCALL_BY_NAME                                       'build'
         26        SEND_VAR_EX                                              !2
         27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0  $19     
         29        FE_FREE                                                  $11
         30      > RETURN                                                   $19
   41    31    > > JMP                                                      ->15
         32    >   FE_FREE                                                  $11
   51    33      > RETURN                                                   !1
   52    34*     > RETURN                                                   null

End of function build

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.09 ms | 1392 KiB | 15 Q