I have a bunch of name-parentname pairs, that I'd like to turn into as few heirarchical tree structures as possible. So for example, these could be the pairings:
Child : Parent H : G F : G G : D E : D A : E B : C C : E D : NULL
Which needs to be transformed into (a) heirarchical tree(s):
D ??? E ? ??? A ? ? ??? B ? ??? C ??? G ??? F ??? H
The end result that I want is a nested set of
<ul> elements, with each
<li> containing the child's name.
There are no inconsistencies in the pairings (child is it's own parent, parent is child's child, etc), so a bunch of optimizations can probably be made.
How, in PHP, would I go from an array containing child=>parent pairs, to a set of Nested
I have a feeling that recursion is involved, but I'm not quite awake enough to think it through.