Create a hierarchical hash from flat source
| From: | Scott Baker | Date: | Wed, 22 Jun 2011 21:53:18 +0000 |
| Subject: | Create a hierarchical hash from flat source | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-313656@lists.php.net to get a copy of this message | ||
I have a bunch of records in a DB that look like
id | parent_id
--------------
1 | 4
2 | 4
3 | 2
4 | 0
5 | 2
6 | 1
7 | 3
8 | 7
9 | 7
I want to build a big has that looks like:
4 -> 1 -> 6
-> 2 -> 3 -> 7 -> 9
-> 5 -> 8
I'm like 90% of the way there, but I can't get my recursive assignment
to work. Has anyone done this before that could offer some pointers?
Here is my sample code thus far:
http://www.perturb.org/tmp/tree.txt
I can get one level of depth, but nothing more than that :(