I'm trying to write a function which will build a tree-structured array based on array of elements defined this way:
array(
'child1' => 'parent',
'child2' => 'parent',
)
so each element has a defined parent and each element has a unique name.
Based on that, here is my array:
myArray(
'Europe' => 'World',
'Africa' => 'World',
'UK' => 'Europe',
'France' => 'Europe',
'London' => 'UK',
)
And I need a function which will return this result:
World => Array (
Europe=> Array (
UK=>Array(
London=>Array()
),
France=>Array()
),
Africa=>Array()
)
This is the closest I could get: http://3v4l.org/OGoXa as you can see, Szczecin is in "World", not in World => Europe => Poland => Szczecin