I use PHP and mySQL with Idiorm. That might not be relevant.
My PHP array
- It's a relationship between parents and childs.
- 0 is the root parent.
- Example: Root parent 0 have the child 33 which have the child 27 which have the child 71.
This array structure can be changed if needed for solving the problem.
array (
33 =>
array (
0 => '27',
1 => '41',
),
27 =>
array (
0 => '64',
1 => '71',
),
0 =>
array (
0 => '28',
1 => '29',
2 => '33',
),
)
My hierarchical result
Something like this, but as an array...
0 =>
28
29
33
27 =>
64
71
41
Information
- The depth are unkown and it can be unlimited. I tried foreach, but it might not be the way.
My own thoughts
- Some recursive function?
- Some while loops?
I tried both of the above, just got a mess. It's a brainer.
See Question&Answers more detail:os