MYSQL returns an array as shown below. I am using column: 'id_parent' to self reference the table to create hierarchy. So an entry with an 'id' of 2 can be the parent of any entry with a 'id_parent' of 2, and so on.
Array
(
[1] => Array
(
[id] => 2
[name] => About
[id_parent] => NULL
)
[2] => Array
(
[id] => 4
[name] => About Child
[id_parent] => 2
)
[3] => Array
(
[id] => 5
[name] => About Child's Child
[id_parent] => 4
)
)
How can I nest the children into an array within their parent array
Array
(
[1] => Array
(
[id] => 2
[name] => About
[id_parent] =>
[children] => Array
(
[id] => 4
[name] => About Child
[id_parent] => 2
[children] => Array
(
[id] => 5
[name] => About Child's Child
[id_parent] => 4
)
)
)
)
References, with the advantages that order doesn't matter (childnodes can come before their parentnodes):