I have an array containing namespace information:
$array = [
['App', 'Classes', 'Auth'],
['App', 'Classes', 'Auth'],
['App', 'Classes', 'Middleware'],
['App', 'Classes', 'Phone'],
['App', 'Classes', 'Auth'],
['App', 'Mail'],
['App', 'Mail', 'Sender'],
['App', 'Box'],
];
Now I want to build a single array or object that should show the namespace information in an hirachic way:
$result = [
['App' =>
['Classes' =>
[
'Auth',
'Middleware',
'Phone',
]
],
['Mail' =>
['Sender']
],
['Box'] => []
]
]
I have tried some recursive functions, but all I get is a flat array...
private function createNamespaceHirachy( $namespaces ) {
foreach ($namespaces as $index => $namespace) {
$namespaces[$namespace] = [];
$namespaces[$namespace] = $this->createNamespaceHirachy($namespaces[$namespace]);
}
return $namespaces;
}
Sorry, it may be much more simple, but I'm brainstuck :-/