Greetings, consider the following array, where each key is the idGroup
Array
(
[10] => Array
(
[vchTitle] => Main group with id #10
[idParent] => 0
)
[19] => Array
(
[vchTitle] => Sub-group with id #19
[idParent] => 10
)
[33] => Array
(
[vchTitle] => Sub-sub-group with id #33
[idParent] => 19
)
[43] = Array
(
[vchTitle] => Sub-group with id #43, no child
[idParent] => 10
)
[17] => Array
(
[vchTitle] => Main group with id #17, no child
[idParent] => 0
)
)
what i need to do is rebuild this array, using a multidimensionnal structure, with the following basic rule: if the value of idParent is zero, then this is a main group, which is not part of a parent group, otherwize, it is a sub-group (or sub-sub-group, or sub-sub-sub...-group), which is part of the idParent, which relates to idGroup
im having a hard time traversing the returned results, and building the multi-dimensionnal array properlly.
Ultimetelly, the array would end up with something like :
Array
(
[10] => Array
(
[vchTitle] => Main group with id #10
[childs] => Array
(
[19] => Array
(
[vchTitle] => Sub-group with id #19
[idParent] => 10
[childs] => Array
(
[33] => Array
(
[vchTitle] => Sub-sub-group with id #33
[idParent] => 19
[childs] =>
)
)
)
)
[43] = Array
(
[vchTitle] => Sub-group with id #43, no child
[idParent] => 10
[childs] =>
)
)
)
[17] => Array
(
[vchTitle] => Main group with id #17, no child
[childs] =>
)
)
You get idea (i hope) 🙂
Thanks for any pointers.