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) - 1; } } for($i = 0; $i < $depth; $i++) { // run through lines foreach($lines as $line) { $values = explode(' / ', $line); $array[] = $values[$depth]; } } var_dump($array);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 array(32) { [0]=> string(6) "1.Liga" [1]=> string(6) "1.Liga" [2]=> string(6) "2.Liga" [3]=> string(6) "2.Liga" [4]=> string(6) "2.Liga" [5]=> string(6) "1.Liga" [6]=> string(6) "1.Liga" [7]=> string(6) "2.Liga" [8]=> string(6) "2.Liga" [9]=> string(6) "3.Liga" [10]=> string(6) "1.Liga" [11]=> string(6) "1.Liga" [12]=> string(6) "2.Liga" [13]=> NULL [14]=> NULL [15]=> NULL [16]=> string(6) "1.Liga" [17]=> string(6) "1.Liga" [18]=> string(6) "2.Liga" [19]=> string(6) "2.Liga" [20]=> string(6) "2.Liga" [21]=> string(6) "1.Liga" [22]=> string(6) "1.Liga" [23]=> string(6) "2.Liga" [24]=> string(6) "2.Liga" [25]=> string(6) "3.Liga" [26]=> string(6) "1.Liga" [27]=> string(6) "1.Liga" [28]=> string(6) "2.Liga" [29]=> NULL [30]=> NULL [31]=> NULL }
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: 2 in /in/JocrI on line 35 Notice: Undefined index: 2 in /in/JocrI on line 35 Notice: Undefined index: 2 in /in/JocrI on line 35 Notice: Undefined index: 2 in /in/JocrI on line 35 Notice: Undefined index: 2 in /in/JocrI on line 35 Notice: Undefined index: 2 in /in/JocrI on line 35 array(32) { [0]=> string(6) "1.Liga" [1]=> string(6) "1.Liga" [2]=> string(6) "2.Liga" [3]=> string(6) "2.Liga" [4]=> string(6) "2.Liga" [5]=> string(6) "1.Liga" [6]=> string(6) "1.Liga" [7]=> string(6) "2.Liga" [8]=> string(6) "2.Liga" [9]=> string(6) "3.Liga" [10]=> string(6) "1.Liga" [11]=> string(6) "1.Liga" [12]=> string(6) "2.Liga" [13]=> NULL [14]=> NULL [15]=> NULL [16]=> string(6) "1.Liga" [17]=> string(6) "1.Liga" [18]=> string(6) "2.Liga" [19]=> string(6) "2.Liga" [20]=> string(6) "2.Liga" [21]=> string(6) "1.Liga" [22]=> string(6) "1.Liga" [23]=> string(6) "2.Liga" [24]=> string(6) "2.Liga" [25]=> string(6) "3.Liga" [26]=> string(6) "1.Liga" [27]=> string(6) "1.Liga" [28]=> string(6) "2.Liga" [29]=> NULL [30]=> NULL [31]=> NULL }
Output for 4.3.0 - 5.2.17
Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 Notice: Undefined offset: 2 in /in/JocrI on line 35 array(32) { [0]=> string(6) "1.Liga" [1]=> string(6) "1.Liga" [2]=> string(6) "2.Liga" [3]=> string(6) "2.Liga" [4]=> string(6) "2.Liga" [5]=> string(6) "1.Liga" [6]=> string(6) "1.Liga" [7]=> string(6) "2.Liga" [8]=> string(6) "2.Liga" [9]=> string(6) "3.Liga" [10]=> string(6) "1.Liga" [11]=> string(6) "1.Liga" [12]=> string(6) "2.Liga" [13]=> NULL [14]=> NULL [15]=> NULL [16]=> string(6) "1.Liga" [17]=> string(6) "1.Liga" [18]=> string(6) "2.Liga" [19]=> string(6) "2.Liga" [20]=> string(6) "2.Liga" [21]=> string(6) "1.Liga" [22]=> string(6) "1.Liga" [23]=> string(6) "2.Liga" [24]=> string(6) "2.Liga" [25]=> string(6) "3.Liga" [26]=> string(6) "1.Liga" [27]=> string(6) "1.Liga" [28]=> string(6) "2.Liga" [29]=> NULL [30]=> NULL [31]=> NULL }