- var_dump: documentation ( source)
- explode: documentation ( source)
<?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);