berlinsurfer: Nested Sets als Multidimensionales Array

Hallo liebe Gemeinde,
habe folgendes (nicht ganz triviales) Problem:
ich habe eine Tabelle mittels modified preorder tress traversal (aka nested sets) und möchte diese gerne in ein multidimensionales array transformieren.
was ich habe:
1. query:

    $sql = "SELECT node.title, node.id as id, (COUNT(parent.id) - 1) AS depth  
        FROM #__jpay_plans AS node,  
        #__jpay_plans AS parent  
        WHERE node.lft BETWEEN parent.lft AND parent.rgt  
        GROUP BY node.id  
        ORDER BY node.lft";  

2. funktion:

  function nestify( &$arrs, $depth_key = 'depth' ) {  
    $nested = array();  
    $depths = array();  
  
    foreach( $arrs as $key => $arr ) {  
      if( $arr[$depth_key] == 0 ) {  
        $nested[$key] = $arr;  
        $depths[$arr[$depth_key] + 1] = $key;  
      } else {  
        $parent =& $nested;  
        for( $i = 1; $i <= ( $arr[$depth_key] ); $i++ ) {  
          $parent =& $parent[$depths[$i]];  
        }  
        $parent[$key] = $arr;  
        $depths[$arr[$depth_key] + 1] = $key;  
      }  
    }  
    return $nested;  
  }  

ich brauche das array jedoch folgendermaßen:
("node1",
"children" => array("node2", "children" => array("node3")));
etc. mir kommt es in diesem zusammenhang auf den key "children" an. kann mich da jemand auf die richtige spur bringen ?
vielen dank schon mals aus berlin !

  1. Für alle, die auf diese Seite soßen, hier die Lösung:
    ihr braucht unbedingt die depth aus dem Query.
    Sprich:

    $sql = "SELECT node.title, node.id as id, (COUNT(parent.id) - 1) AS depth
        FROM nested_category AS node,
        nested_category AS parent
        WHERE node.lft BETWEEN parent.lft AND parent.rgt
        GROUP BY node.id
        ORDER BY node.lft";
    $res = load() // wie auch immer;
    $n = _toHierarchy(&$res);

    Viel Spaß damit.

    function _toHierarchy(&$collection) {
        $trees = array();
        $l = 0;

    if (count($collection) > 0) {
          $stack = array();
          foreach ($collection as $node) {
            $item = $node;
            $item["children"] = array();
            $l = count($stack);
            while ($l > 0 && $stack[$l-1]['depth'] >= $item['depth']) {
              array_pop($stack);
              $l--;
            }
            if ($l == 0) {
              $i = count($trees);
              $trees[$i] = $item;
              $stack[] = &$trees[$i];
            } else {
              $i = count($stack[$l-1]["children"]);
              $stack[$l-1]["children"][$i]=$item;
              $stack[]=&$stack[$l-1]["children"][$i];
            }
          }
        }
        return $trees;
      }