I'm looking for a function that can create a hierarchical array but only for some childs.
this example seems to be good : Recursive function to generate multidimensional array from database result
But I want parents just for some IDs. For example :
+-------+---------------+---------------------------+
| id | parent_id | title |
+-------+---------------+---------------------------+
| 1 | 0 | Parent Page |
| 2 | 1 | Sub Page |
| 3 | 2 | Sub Sub Page |
| 4 | 0 | Another Parent Page |
| 5 | 1 | Sub Page 2 |
+-------+---------------+---------------------------+
I want only hierarchy for id 2, 4 and 5.
And return me something like this :
Array
(
[0] => Array
(
[id] => 1
[parent_id] => 0
[title] => Parent Page
[children] => Array
(
[0] => Array
(
[id] => 2
[parent_id] => 1
[title] => Sub Page
),
[1] => Array
(
[id] => 5
[parent_id] => 1
[title] => Sub Page 2
)
)
)
[1] => Array
(
[id] => 4
[parent_id] => 0
[title] => Another Parent Page
)
)
2, 4 and 5 should be smallest childrens and nothing under them.
To resume, what I want is exactly the same than linked post, but my smallest leafs should be only leaf's id present in an array [2,4,5]
I don't know if someone understand my problem...
Thanks a lot
Edit: I have update and add example with id = 5.