3v4l.org

run code in 200+ php & hhvm versions
<?php $string = "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"; class ArrayStacker { public function stackArray($string) { $array = $this->splitString($string); $stackedArray = array(); foreach($array as $row) { $stackedArray[] = $this->_stack($row); } return $stackedArray; } /** * Split the whole string into a big array * * @param string $string * @return array */ protected function splitString($string) { $lines = explode("\n", $string); $i = 0; $array = array(); foreach($lines as $line) { $values = explode(' / ', $line); foreach($values as $v => $value) { $values[$v] = trim($value); // make sure we got no whitespaces } $array[$i] = $values; $i++; } return $array; } protected function _stack($array) { $stackedArray = array(); $key = array_shift($array); if(count($array) == 1) { $stackedArray[$key] = $array[0]; // that's a single value } else { $stackedArray[$key] = $this->_stack($array); } return $stackedArray; } } $arrayStacker = new ArrayStacker(); var_dump($arrayStacker->stackArray($string));
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/VeSl4
function name:  (null)
number of ops:  12
compiled vars:  !0 = $string, !1 = $arrayStacker
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  17     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        NOP                                                      
  63     2        NEW                                              $4      :-5
         3        DO_FCALL                                      0          
         4        ASSIGN                                                   !1, $4
  64     5        INIT_FCALL                                               'var_dump'
         6        INIT_METHOD_CALL                                         !1, 'stackArray'
         7        SEND_VAR_EX                                              !0
         8        DO_FCALL                                      0  $7      
         9        SEND_VAR                                                 $7
        10        DO_ICALL                                                 
        11      > RETURN                                                   1

Class ArrayStacker:
Function stackarray:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
Jump found. Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
Jump found. Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
Jump found. Position 1 = -2
Branch analysis from position: 14
filename:       /in/VeSl4
function name:  stackArray
number of ops:  17
compiled vars:  !0 = $string, !1 = $array, !2 = $stackedArray, !3 = $row
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  21     0  E >   RECV                                             !0      
  22     1        INIT_METHOD_CALL                                         'splitString'
         2        SEND_VAR_EX                                              !0
         3        DO_FCALL                                      0  $4      
         4        ASSIGN                                                   !1, $4
  23     5        ASSIGN                                                   !2, <array>
  24     6      > FE_RESET_R                                       $7      !1, ->14
         7    > > FE_FETCH_R                                               $7, !3, ->14
  25     8    >   INIT_METHOD_CALL                                         '_stack'
         9        SEND_VAR_EX                                              !3
        10        DO_FCALL                                      0  $9      
        11        ASSIGN_DIM                                               !2
        12        OP_DATA                                                  $9
        13      > JMP                                                      ->7
        14    >   FE_FREE                                                  $7
  27    15      > RETURN                                                   !2
  28    16*     > RETURN                                                   null

End of function stackarray

Function splitstring:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
Jump found. Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
Jump found. Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
Jump found. Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
Jump found. Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
Jump found. Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 24
Branch analysis from position: 30
Jump found. Position 1 = -2
Branch analysis from position: 30
filename:       /in/VeSl4
function name:  splitString
number of ops:  33
compiled vars:  !0 = $string, !1 = $lines, !2 = $i, !3 = $array, !4 = $line, !5 = $values, !6 = $value, !7 = $v
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  36     0  E >   RECV                                             !0      
  37     1        INIT_FCALL                                               'explode'
         2        SEND_VAL                                                 '%0A'
         3        SEND_VAR                                                 !0
         4        DO_ICALL                                         $8      
         5        ASSIGN                                                   !1, $8
  38     6        ASSIGN                                                   !2, 0
  39     7        ASSIGN                                                   !3, <array>
  40     8      > FE_RESET_R                                       $12     !1, ->30
         9    > > FE_FETCH_R                                               $12, !4, ->30
  41    10    >   INIT_FCALL                                               'explode'
        11        SEND_VAL                                                 '+%2F+'
        12        SEND_VAR                                                 !4
        13        DO_ICALL                                         $13     
        14        ASSIGN                                                   !5, $13
  42    15      > FE_RESET_R                                       $15     !5, ->24
        16    > > FE_FETCH_R                                       ~16     $15, !6, ->24
        17    >   ASSIGN                                                   !7, ~16
  43    18        INIT_FCALL                                               'trim'
        19        SEND_VAR                                                 !6
        20        DO_ICALL                                         $19     
        21        ASSIGN_DIM                                               !5, !7
        22        OP_DATA                                                  $19
        23      > JMP                                                      ->16
        24    >   FE_FREE                                                  $15
  45    25        ASSIGN_DIM                                               !3, !2
        26        OP_DATA                                                  !5
  46    27        POST_INC                                         ~21     !2
        28        FREE                                                     ~21
        29      > JMP                                                      ->9
        30    >   FE_FREE                                                  $12
  48    31      > RETURN                                                   !3
  49    32*     > RETURN                                                   null

End of function splitstring

Function _stack:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
Jump found. Position 1 = 20
Branch analysis from position: 20
Jump found. Position 1 = -2
Branch analysis from position: 15
Jump found. Position 1 = -2
filename:       /in/VeSl4
function name:  _stack
number of ops:  22
compiled vars:  !0 = $array, !1 = $stackedArray, !2 = $key
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  51     0  E >   RECV                                             !0      
  52     1        ASSIGN                                                   !1, <array>
  53     2        INIT_FCALL                                               'array_shift'
         3        SEND_REF                                                 !0
         4        DO_ICALL                                         $4      
         5        ASSIGN                                                   !2, $4
  54     6        INIT_FCALL                                               'count'
         7        SEND_VAR                                                 !0
         8        DO_ICALL                                         $6      
         9        IS_EQUAL                                         ~7      $6, 1
        10      > JMPZ                                                     ~7, ->15
  55    11    >   FETCH_DIM_R                                      $9      !0, 0
        12        ASSIGN_DIM                                               !1, !2
        13        OP_DATA                                                  $9
        14      > JMP                                                      ->20
  57    15    >   INIT_METHOD_CALL                                         '_stack'
        16        SEND_VAR_EX                                              !0
        17        DO_FCALL                                      0  $11     
        18        ASSIGN_DIM                                               !1, !2
        19        OP_DATA                                                  $11
  59    20    > > RETURN                                                   !1
  60    21*     > RETURN                                                   null

End of function _stack

End of class ArrayStacker.

Generated using Vulcan Logic Dumper, using php 7.3.0