- var_dump: documentation ( source)
- explode: documentation ( source)
- in_array: 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();
foreach($lines as $line) {
$values = explode(' / ', $line);
$depth = 0;
foreach($values as $value) {
if(!in_array($value, $array[$depth])) $array[$depth][] = $value;
$depth++;
}
}
var_dump($array);