Hello,

If anyone have expamples of displaying tree structure.

Say I have array  $result[x][y] with folloowing data

X    Y["ID"]    Y["OWNER"]
0    1               0
1    2               1
2    3               2
3    4               2
4    5               3
5    6               2
6    7               2


So, I want it displayed like

ID1
    ID2
        ID3
            ID5
        ID4
        ID6
        ID7

========================

Please, help I tryed to do it with recursing but failed.

There is a test function which shows that php doesnt support recursing
well:-

function parse($id){
    global $result;
    $idarr=getChildren($id); // thsi function return indexes of child nodes
of $id or empt array.
    for ($i=0;$i<count($idarr);$i++){
        echo $result[$idarr[$i]]["id"];
        $id=$result[$idarr[$i]]["id"];
        parse($id);
    }
}

Actually it should print me only nodes which has childs, like ID1, ID2 and
ID3 but it shows everything.

getChildren-
function getChildren($id){
    global $result;
    $children = array();
    for ($i=0;$i<count($result);$i++){
        if ($id==$result[$i]["owner"]){
            while ($i<count($result)){
                if ($id==$result[$i]["owner"]){
                array_push($children,$i);
                }
                else{
                break;
                }
                $i++;
            }
            break;
        }
    }
return $children;
}



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to