Im stuck in a mire of infinite child/parent relationships and trying to print out an organogram type tree.

I have widgets with an id... a widget can have a parent widget and reference its id as the sub-widget's parent_id... now I need to print this out in a hierarchy, and all I have is an array with all of my widgets in it.

If I try a foreach loop, I can say for array[0] - check through the other widgets and find those that reference array[0] as the parent, and print them out. But, if that second level widget also has kids, then how do I find its kids... and so on for infinite number of kids...?

Brain. melting.

Post the structure of the array. I think we will have to use recursion here to traverse the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.