3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = array( array('left' => 1, 'right' => 11, 'x' => 'A'), array('left' => 2, 'right' => 4, 'x' => 'B'), array('left' => 5, 'right' => 10, 'x' => 'C'), array('left' => 6, 'right' => 7, 'x' => 'D'), array('left' => 8, 'right' => 9, 'x' => 'E'), array('left' => 12, 'right' => 13, 'x' => 'F'), ); function createTree ($category, $left = 0, $right = null) { $tree = array(); foreach ($category as $cat => $data) { if ($data['left'] == $left + 1 && (is_null($right) || $data['right'] < $right)) { $tree[$cat] = createTree($category, $data['left'], $data['right']); $left = $data['right']; } } return $tree; } $tree = createTree ($category); print_r($tree);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CgGcv
function name:  (null)
number of ops:  9
compiled vars:  !0 = $category, !1 = $tree
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   26     1        INIT_FCALL                                               'createtree'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   27     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function createtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 32
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 32
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 31
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 31
Branch analysis from position: 16
Branch analysis from position: 17
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/CgGcv
function name:  createTree
number of ops:  35
compiled vars:  !0 = $category, !1 = $left, !2 = $right, !3 = $tree, !4 = $data, !5 = $cat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      null
   14     3        ASSIGN                                                   !3, <array>
   15     4      > FE_RESET_R                                       $7      !0, ->32
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->32
          6    >   ASSIGN                                                   !5, ~8
   17     7        FETCH_DIM_R                                      ~10     !4, 'left'
          8        ADD                                              ~11     !1, 1
          9        IS_EQUAL                                         ~12     ~10, ~11
         10      > JMPZ_EX                                          ~12     ~12, ->17
         11    >   TYPE_CHECK                                    2  ~13     !2
         12      > JMPNZ_EX                                         ~13     ~13, ->16
         13    >   FETCH_DIM_R                                      ~14     !4, 'right'
         14        IS_SMALLER                                       ~15     ~14, !2
         15        BOOL                                             ~13     ~15
         16    >   BOOL                                             ~12     ~13
         17    > > JMPZ                                                     ~12, ->31
   19    18    >   INIT_FCALL_BY_NAME                                       'createTree'
         19        SEND_VAR_EX                                              !0
         20        CHECK_FUNC_ARG                                           
         21        FETCH_DIM_FUNC_ARG                               $17     !4, 'left'
         22        SEND_FUNC_ARG                                            $17
         23        CHECK_FUNC_ARG                                           
         24        FETCH_DIM_FUNC_ARG                               $18     !4, 'right'
         25        SEND_FUNC_ARG                                            $18
         26        DO_FCALL                                      0  $19     
         27        ASSIGN_DIM                                               !3, !5
         28        OP_DATA                                                  $19
   20    29        FETCH_DIM_R                                      ~20     !4, 'right'
         30        ASSIGN                                                   !1, ~20
   15    31    > > JMP                                                      ->5
         32    >   FE_FREE                                                  $7
   23    33      > RETURN                                                   !3
   24    34*     > RETURN                                                   null

End of function createtree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.41 ms | 1394 KiB | 16 Q