3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 35 Warning: in_array() expects parameter 2 to be array, null given in /in/LQZhU on line 35 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 3.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 1 in /in/LQZhU on line 35 Warning: in_array() expects parameter 2 to be array, null given in /in/LQZhU on line 35 Notice: Undefined index: Meisterschaft in /in/LQZhU on line 36 Notice: Undefined index: Meisterschaft in /in/LQZhU on line 36 Notice: Undefined index: Weltmeister in /in/LQZhU on line 36 Notice: Undefined offset: 0 in /in/LQZhU on line 35 Warning: in_array() expects parameter 2 to be array, null given in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 array(4) { [3]=> array(1) { [""]=> NULL } [2]=> array(6) { ["Germany"]=> string(6) "2.Liga" ["1.Liga"]=> NULL ["2.Liga"]=> NULL ["England"]=> string(6) "3.Liga" ["3.Liga"]=> NULL [""]=> NULL } [1]=> array(7) { ["Football"]=> string(7) "England" ["Germany"]=> string(6) "2.Liga" ["England"]=> string(6) "3.Liga" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" ["Meisterschaft"]=> NULL ["Weltmeister"]=> NULL } [0]=> array(4) { [""]=> string(7) "Fechten" ["Football"]=> string(7) "England" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" } }
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 4 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 4 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 4 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 4 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 Notice: Undefined index: 4 in /in/LQZhU on line 36 Notice: Undefined index: 3 in /in/LQZhU on line 36 array(4) { [3]=> array(1) { [""]=> NULL } [2]=> array(6) { ["Germany"]=> string(6) "2.Liga" ["1.Liga"]=> NULL ["2.Liga"]=> NULL ["England"]=> string(6) "3.Liga" ["3.Liga"]=> NULL [""]=> NULL } [1]=> array(7) { ["Football"]=> string(7) "England" ["Germany"]=> string(6) "2.Liga" ["England"]=> string(6) "3.Liga" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" ["Meisterschaft"]=> NULL ["Weltmeister"]=> NULL } [0]=> array(4) { [""]=> string(7) "Fechten" ["Football"]=> string(7) "England" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" } }
Output for 4.3.2 - 5.2.17
Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 35 Warning: in_array(): Wrong datatype for second argument in /in/LQZhU on line 35 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 3.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 1 in /in/LQZhU on line 35 Warning: in_array(): Wrong datatype for second argument in /in/LQZhU on line 35 Notice: Undefined index: Meisterschaft in /in/LQZhU on line 36 Notice: Undefined index: Meisterschaft in /in/LQZhU on line 36 Notice: Undefined index: Weltmeister in /in/LQZhU on line 36 Notice: Undefined offset: 0 in /in/LQZhU on line 35 Warning: in_array(): Wrong datatype for second argument in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 array(4) { [3]=> array(1) { [""]=> NULL } [2]=> array(6) { ["Germany"]=> string(6) "2.Liga" ["1.Liga"]=> NULL ["2.Liga"]=> NULL ["England"]=> string(6) "3.Liga" ["3.Liga"]=> NULL [""]=> NULL } [1]=> array(7) { ["Football"]=> string(7) "England" ["Germany"]=> string(6) "2.Liga" ["England"]=> string(6) "3.Liga" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" ["Meisterschaft"]=> NULL ["Weltmeister"]=> NULL } [0]=> array(4) { [""]=> string(7) "Fechten" ["Football"]=> string(7) "England" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" } }
Output for 4.3.0 - 4.3.1
Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 3 in /in/LQZhU on line 36 Notice: Undefined offset: 4 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 35 Warning: in_array() [http://www.php.net/function.in-array]: Wrong datatype for second argument in /in/LQZhU on line 35 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined index: 3.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 1.Liga in /in/LQZhU on line 36 Notice: Undefined index: 2.Liga in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 2 in /in/LQZhU on line 36 Notice: Undefined offset: 1 in /in/LQZhU on line 35 Warning: in_array() [http://www.php.net/function.in-array]: Wrong datatype for second argument in /in/LQZhU on line 35 Notice: Undefined index: Meisterschaft in /in/LQZhU on line 36 Notice: Undefined index: Meisterschaft in /in/LQZhU on line 36 Notice: Undefined index: Weltmeister in /in/LQZhU on line 36 Notice: Undefined offset: 0 in /in/LQZhU on line 35 Warning: in_array() [http://www.php.net/function.in-array]: Wrong datatype for second argument in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 Notice: Undefined offset: -1 in /in/LQZhU on line 35 array(4) { [3]=> array(1) { [""]=> NULL } [2]=> array(6) { ["Germany"]=> string(6) "2.Liga" ["1.Liga"]=> NULL ["2.Liga"]=> NULL ["England"]=> string(6) "3.Liga" ["3.Liga"]=> NULL [""]=> NULL } [1]=> array(7) { ["Football"]=> string(7) "England" ["Germany"]=> string(6) "2.Liga" ["England"]=> string(6) "3.Liga" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" ["Meisterschaft"]=> NULL ["Weltmeister"]=> NULL } [0]=> array(4) { [""]=> string(7) "Fechten" ["Football"]=> string(7) "England" ["Hockey"]=> string(7) "Germany" ["Fechten"]=> string(11) "Weltmeister" } }