CodeIgniter Forums
Nested set, returning array with children - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Nested set, returning array with children (/showthread.php?tid=45563)



Nested set, returning array with children - El Forum - 09-26-2011

[eluser]GeXus[/eluser]
I'm using the Nested set plugin for a tree. I'm trying to return a multidimensional array that includes a nodes children, for example:

Code:
Array
(
[0] => Array
   (
    [id] => 22
    [name] => Name
    [children] => Array(
     [0] = Array(
       [id] => 23
       [name] => Child Name
      )
     [1] = Array(
      [id] => 24
      [name] => Child Name
     )
     )
   )
[1] => Array
   (
    [id] => 25
    [name] => Name
    )
}

This is what I would like to return, but I'm seriously so lost. I've spent all day trying to do this and I have no clue.

I've tried creating a recursive function that returns the children of each node and builds an array, but it just doesn't seem to work, always an endless loop, even with checks in place, I've tried iterating through the full tree and building a new array and it had issues going deeper than one level.

Any help would be amazing! Thank you!