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); if(isset($values[$depth])) $array[] = $values[$depth]; } } var_dump($array);
Output for 4.3.0 - 7.1.0
array(26) { [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]=> string(6) "1.Liga" [14]=> string(6) "1.Liga" [15]=> string(6) "2.Liga" [16]=> string(6) "2.Liga" [17]=> string(6) "2.Liga" [18]=> string(6) "1.Liga" [19]=> string(6) "1.Liga" [20]=> string(6) "2.Liga" [21]=> string(6) "2.Liga" [22]=> string(6) "3.Liga" [23]=> string(6) "1.Liga" [24]=> string(6) "1.Liga" [25]=> string(6) "2.Liga" }