Hello, I was wondering how I would convert an existing structure to a tree. What I want is basically a family tree. What I have is the following:
array (
array(id => 123, p1 => 567, p2 => 765),
array(id => 321, p1 => 567, p2 => 890),
array(id => 333, p1 => 123, p2 => null),
array(id => 444, p1 => null, p2 => null),
etc.
);
It's an array of associative arrays showing each element in the family tree as well the their parent(s). An element can have one, two, or zero parents. If they have one parent, it is ALWAYS p1. If an element has no parents, it is not necessarily the root, because if there are two parents, one parent can have no parents and the other can still have one or two. And of course, there doesn't necessarily have to have just one root.
What I ultimately want is to display the tree graphically, but I am way too dumb to be able to convert this into a tree structure. I actually saw a post on this site asking a similar question (http://bytes.com/topic/php/answers/4403 -algorithm-creating-tree-structure-linke d-list), but it only deals with one parent. It might be a simple transition to add another parent, but I'm just not grasping this very well. If anyone has any insight into this or can point me in the right direction it would be greatly appreciated.
Thanks.
array (
array(id => 123, p1 => 567, p2 => 765),
array(id => 321, p1 => 567, p2 => 890),
array(id => 333, p1 => 123, p2 => null),
array(id => 444, p1 => null, p2 => null),
etc.
);
It's an array of associative arrays showing each element in the family tree as well the their parent(s). An element can have one, two, or zero parents. If they have one parent, it is ALWAYS p1. If an element has no parents, it is not necessarily the root, because if there are two parents, one parent can have no parents and the other can still have one or two. And of course, there doesn't necessarily have to have just one root.
What I ultimately want is to display the tree graphically, but I am way too dumb to be able to convert this into a tree structure. I actually saw a post on this site asking a similar question (http://bytes.com/topic/php/answers/4403 -algorithm-creating-tree-structure-linke d-list), but it only deals with one parent. It might be a simple transition to add another parent, but I'm just not grasping this very well. If anyone has any insight into this or can point me in the right direction it would be greatly appreciated.
Thanks.
Comment