Welcome Guest, Not a member yet? Register   Sign In
Nested set, returning array with children
#1

[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!




Theme © iAndrew 2016 - Forum software by © MyBB