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 = 52
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 52
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 50
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 50
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 49
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 49
Branch analysis from position: 39
Branch analysis from position: 49
Branch analysis from position: 20
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 50
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 55
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 55
Branch analysis from position: 65
Branch analysis from position: 55
Branch analysis from position: 52
filename:       /in/sHf5T
function name:  (null)
number of ops:  66
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, ->52
          7    > > FE_FETCH_R                                               $13, !2, ->52
   13     8    >   COUNT                                            ~14     !2
          9        ASSIGN                                                   !1, ~14
   14    10      > FE_RESET_R                                       $16     !2, ->50
         11    > > FE_FETCH_R                                       ~17     $16, !3, ->50
         12    >   ASSIGN                                                   !4, ~17
   15    13        NOP                                                      
         14        FAST_CONCAT                                      ~19     'lev_', !4
         15        ASSIGN                                                   !5, ~19
   16    16        TYPE_CHECK                                  128  ~21     !5
         17        BOOL_NOT                                         ~22     ~21
         18      > JMPZ                                                     ~22, ->20
   17    19    >   ASSIGN                                                   !5, <array>
   19    20    >   INIT_FCALL                                               'array_search'
         21        SEND_VAR                                                 !3
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $24     
         24        ASSIGN                                                   !6, $24
   20    25        TYPE_CHECK                                    4          !6
         26      > JMPZ                                                     ~26, ->49
   21    27    >   IS_EQUAL                                                 !4, 0
         28      > JMPZ                                                     ~27, ->32
   22    29    >   ASSIGN_DIM                                               !5
         30        OP_DATA                                                  !3
         31      > JMP                                                      ->49
   24    32    >   SUB                                              ~29     !4, 1
         33        CONCAT                                           ~30     'lev_', ~29
         34        ASSIGN                                                   !7, ~30
   25    35        TYPE_CHECK                                  128  ~32     !7
         36        BOOL_NOT                                         ~33     ~32
         37      > JMPZ                                                     ~33, ->39
   26    38    >   ASSIGN                                                   !7, <array>
   28    39    >   INIT_FCALL                                               'array_search'
         40        SUB                                              ~35     !4, 1
         41        FETCH_DIM_R                                      ~36     !2, ~35
         42        SEND_VAL                                                 ~36
         43        SEND_VAR                                                 !7
         44        DO_ICALL                                         $37     
         45        ASSIGN                                                   !8, $37
   29    46      > JMPZ                                                     !8, ->49
   30    47    >   ASSIGN_DIM                                               !5, !8
         48        OP_DATA                                                  !3
   14    49    > > JMP                                                      ->11
         50    >   FE_FREE                                                  $16
   12    51      > JMP                                                      ->7
         52    >   FE_FREE                                                  $13
   37    53        ASSIGN                                                   !9, 0
         54      > JMP                                                      ->63
   38    55    >   NOP                                                      
         56        FAST_CONCAT                                      ~41     'lev_', !9
         57        ASSIGN                                                   !5, ~41
   39    58        INIT_FCALL                                               'print_r'
         59        FETCH_R                      local               ~43     !5
         60        SEND_VAL                                                 ~43
         61        DO_ICALL                                                 
   37    62        PRE_INC                                                  !9
         63    >   IS_SMALLER                                               !9, !1
         64      > JMPNZ                                                    ~46, ->55
   40    65    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.48 ms | 1400 KiB | 17 Q