I have an array containing a lot category strings like
Cars > Model1
Cars > Model1 > Accessories
Cars > Model1 > Something
Cars > Model2
Cars > Model3
which I want to recursively transform into a multidimensional array where "Cars" is the parent element of Model1, Model2 and Model3.
And of course, "Accessories" and "Something" would be child elements of Model1.
Have been trying to work out the logic behind this for quite some time now, and I just can't seem to figure it out...
Edit: What I have so far, it's not much. As mentioned, can't seem to figure out the logic behind how to develop this.
$array = array(
'Cars > Model1',
'Cars > Model1 > Accessories',
'Cars > Model1 > Something',
'Cars > Model2',
'Cars > Model3'
);
for ($i = 0; $i < count($array); $i++) {
$name = explode('>', $array[$i]);
// somehow check if the current "name" is already pushed to a new array - if it is, then add as a child.
}