|
Posted by Michael Fesser on 11/26/07 00:41
..oO(alexandis@gmail.com)
>I have the following multi array like this:
>[0] => [ [0] => "A", [1] => "B", [2] => "C" ]
>[1] => [ [0] => "A", [1] => "C", [2] => "D" ]
>[2] => [ [0] => "B", [1] => "A", [2] => "B" ]
>[3] => [ [0] => "B", [1] => "A", [2] => "D" ]
>
>It should be transformed into this:
>["A"] => [
> ["B"] => [
> "C"
> ],
> ["C"] => [
> "D"
> ]
> ],
>["B"] => [
> ["A"] => [
> "B", "D"
> ]
> ]
>
>- that is to say, i need to split the above structure into classes,
>subclasses, subsubclasses and so on, depth is variable...
<?php
$test = array(
array('A', 'B', 'C'),
array('A', 'C', 'D'),
array('B', 'A', 'B'),
array('B', 'A', 'D'),
);
$result = array();
foreach ($test as $array) {
$current = &$result;
foreach ($array as $item) {
$current = &$current[$item];
}
}
print_r($result);
?>
HTH
Micha
[Back to original message]
|