3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = "Football / Germany / 1.Liga Football / Germany / 1.Liga Football / Germany / 2.Liga Football / Germany / 2.Liga Football / Germany / 2.Liga Football / England / 1.Liga Football / England / 1.Liga Football / England / 2.Liga Football / England / 2.Liga Football / England / 3.Liga Hockey / Germany / 1.Liga Hockey / Germany / 1.Liga Hockey / Germany / 2.Liga Fechten / Meisterschaft Fechten / Meisterschaft Fechten / Weltmeister"; $lines = explode("\n", $strings); $array = array(); $depth = 0; foreach($lines as $line) { $values = explode(' / ', $line); // find out how deep we have to go if(count($values) > $depth) { $depth = count($values); } } for($i = $depth; $i >= 0; $i--) { // run through lines foreach($lines as $line) { $values = explode(' / ', $line); if(isset($values[$i]) && !in_array($values[$i], $array[$i])) $array[$i][$values[$i-1]] = $values[$i]; //$array[$i][$values[$i]] = $array[$i+1][$values[$i]]; } } var_dump($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 24
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 49
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 49
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 48
Branch analysis from position: 41
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 24
Branch analysis from position: 53
Branch analysis from position: 24
Branch analysis from position: 49
Branch analysis from position: 21
filename:       /in/rJLeZ
function name:  (null)
number of ops:  57
compiled vars:  !0 = $strings, !1 = $lines, !2 = $array, !3 = $depth, !4 = $line, !5 = $values, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'Football+%2F+Germany+%2F+1.Liga%0AFootball+%2F+Germany+%2F+1.Liga%0AFootball+%2F+Germany+%2F+2.Liga%0AFootball+%2F+Germany+%2F+2.Liga%0AFootball+%2F+Germany+%2F+2.Liga%0AFootball+%2F+England+%2F+1.Liga%0AFootball+%2F+England+%2F+1.Liga%0AFootball+%2F+England+%2F+2.Liga%0AFootball+%2F+England+%2F+2.Liga%0AFootball+%2F+England+%2F+3.Liga%0AHockey+%2F+Germany+%2F+1.Liga%0AHockey+%2F+Germany+%2F+1.Liga%0AHockey+%2F+Germany+%2F+2.Liga%0AFechten+%2F+Meisterschaft%0AFechten+%2F+Meisterschaft%0AFechten+%2F+Weltmeister'
   19     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%0A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !1, $8
   20     6        ASSIGN                                                   !2, <array>
   22     7        ASSIGN                                                   !3, 0
   23     8      > FE_RESET_R                                       $12     !1, ->21
          9    > > FE_FETCH_R                                               $12, !4, ->21
   24    10    >   INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '+%2F+'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !5, $13
   26    15        COUNT                                            ~15     !5
         16        IS_SMALLER                                               !3, ~15
         17      > JMPZ                                                     ~16, ->20
   27    18    >   COUNT                                            ~17     !5
         19        ASSIGN                                                   !3, ~17
   23    20    > > JMP                                                      ->9
         21    >   FE_FREE                                                  $12
   31    22        ASSIGN                                                   !6, !3
         23      > JMP                                                      ->51
   33    24    > > FE_RESET_R                                       $20     !1, ->49
         25    > > FE_FETCH_R                                               $20, !4, ->49
   34    26    >   INIT_FCALL                                               'explode'
         27        SEND_VAL                                                 '+%2F+'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $21     
         30        ASSIGN                                                   !5, $21
   35    31        ISSET_ISEMPTY_DIM_OBJ                         0  ~23     !5, !6
         32      > JMPZ_EX                                          ~23     ~23, ->41
         33    >   INIT_FCALL                                               'in_array'
         34        FETCH_DIM_R                                      ~24     !5, !6
         35        SEND_VAL                                                 ~24
         36        FETCH_DIM_R                                      ~25     !2, !6
         37        SEND_VAL                                                 ~25
         38        DO_ICALL                                         $26     
         39        BOOL_NOT                                         ~27     $26
         40        BOOL                                             ~23     ~27
         41    > > JMPZ                                                     ~23, ->48
         42    >   SUB                                              ~29     !6, 1
         43        FETCH_DIM_R                                      ~30     !5, ~29
         44        FETCH_DIM_R                                      ~32     !5, !6
         45        FETCH_DIM_W                                      $28     !2, !6
         46        ASSIGN_DIM                                               $28, ~30
         47        OP_DATA                                                  ~32
   33    48    > > JMP                                                      ->25
         49    >   FE_FREE                                                  $20
   31    50        PRE_DEC                                                  !6
         51    >   IS_SMALLER_OR_EQUAL                                      0, !6
         52      > JMPNZ                                                    ~34, ->24
   40    53    >   INIT_FCALL                                               'var_dump'
         54        SEND_VAR                                                 !2
         55        DO_ICALL                                                 
         56      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.62 ms | 1400 KiB | 19 Q