3v4l.org

run code in 300+ PHP versions simultaneously
<?php $main = array( array('Women', 'Acces', 'Belts'), array('Women', 'Acces', 'Bangels'), array('Women', 'Top', 'T-Shirts') ); echo "<pre>"; print_r($main); $max_level = 0; foreach($main as $data){ $max_level = count($data); foreach($data as $k => $v) { $level = "lev_$k"; if(!is_array($$level)){ $$level = array(); } $index = array_search($v, $$level); if($index === false){ if($k == 0){ $$level[] = $v; } else { $$parent = "lev_" . ($k-1); if(!is_array($$parent)){ $$parent = array(); } $parent_index = array_search($data[$k-1], $$parent); if($parent_index){ $$level[$parent_index] = $v; } } } } } for($i = 0;$i< $max_level;$i++){ $level = "lev_$i"; print_r($$level); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 61
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 61
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 59
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 59
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 58
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 58
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 58
Branch analysis from position: 46
Branch analysis from position: 58
Branch analysis from position: 22
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 59
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 64
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 64
Branch analysis from position: 74
Branch analysis from position: 64
Branch analysis from position: 61
filename:       /in/tV1FA
function name:  (null)
number of ops:  75
compiled vars:  !0 = $main, !1 = $max_level, !2 = $data, !3 = $v, !4 = $k, !5 = $level, !6 = $index, !7 = $parent, !8 = $parent_index, !9 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ECHO                                                     '%3Cpre%3E'
    9     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   11     5        ASSIGN                                                   !1, 0
   12     6      > FE_RESET_R                                       $13     !0, ->61
          7    > > FE_FETCH_R                                               $13, !2, ->61
   13     8    >   COUNT                                            ~14     !2
          9        ASSIGN                                                   !1, ~14
   14    10      > FE_RESET_R                                       $16     !2, ->59
         11    > > FE_FETCH_R                                       ~17     $16, !3, ->59
         12    >   ASSIGN                                                   !4, ~17
   15    13        NOP                                                      
         14        FAST_CONCAT                                      ~19     'lev_', !4
         15        ASSIGN                                                   !5, ~19
   16    16        FETCH_R                      local               ~21     !5
         17        TYPE_CHECK                                  128  ~22     ~21
         18        BOOL_NOT                                         ~23     ~22
         19      > JMPZ                                                     ~23, ->22
   17    20    >   FETCH_W                      local               $24     !5
         21        ASSIGN                                                   $24, <array>
   19    22    >   INIT_FCALL                                               'array_search'
         23        SEND_VAR                                                 !3
         24        FETCH_R                      local               ~26     !5
         25        SEND_VAL                                                 ~26
         26        DO_ICALL                                         $27     
         27        ASSIGN                                                   !6, $27
   20    28        TYPE_CHECK                                    4          !6
         29      > JMPZ                                                     ~29, ->58
   21    30    >   IS_EQUAL                                                 !4, 0
         31      > JMPZ                                                     ~30, ->36
   22    32    >   FETCH_W                      local               $31     !5
         33        ASSIGN_DIM                                               $31
         34        OP_DATA                                                  !3
         35      > JMP                                                      ->58
   24    36    >   SUB                                              ~34     !4, 1
         37        CONCAT                                           ~35     'lev_', ~34
         38        FETCH_W                      local               $33     !7
         39        ASSIGN                                                   $33, ~35
   25    40        FETCH_R                      local               ~37     !7
         41        TYPE_CHECK                                  128  ~38     ~37
         42        BOOL_NOT                                         ~39     ~38
         43      > JMPZ                                                     ~39, ->46
   26    44    >   FETCH_W                      local               $40     !7
         45        ASSIGN                                                   $40, <array>
   28    46    >   INIT_FCALL                                               'array_search'
         47        SUB                                              ~42     !4, 1
         48        FETCH_DIM_R                                      ~43     !2, ~42
         49        SEND_VAL                                                 ~43
         50        FETCH_R                      local               ~44     !7
         51        SEND_VAL                                                 ~44
         52        DO_ICALL                                         $45     
         53        ASSIGN                                                   !8, $45
   29    54      > JMPZ                                                     !8, ->58
   30    55    >   FETCH_W                      local               $47     !5
         56        ASSIGN_DIM                                               $47, !8
         57        OP_DATA                                                  !3
   14    58    > > JMP                                                      ->11
         59    >   FE_FREE                                                  $16
   12    60      > JMP                                                      ->7
         61    >   FE_FREE                                                  $13
   37    62        ASSIGN                                                   !9, 0
         63      > JMP                                                      ->72
   38    64    >   NOP                                                      
         65        FAST_CONCAT                                      ~50     'lev_', !9
         66        ASSIGN                                                   !5, ~50
   39    67        INIT_FCALL                                               'print_r'
         68        FETCH_R                      local               ~52     !5
         69        SEND_VAL                                                 ~52
         70        DO_ICALL                                                 
   37    71        PRE_INC                                                  !9
         72    >   IS_SMALLER                                               !9, !1
         73      > JMPNZ                                                    ~55, ->64
   40    74    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.33 ms | 1404 KiB | 17 Q