nodeID = $nodeID;
$this->nodeName = $nodeName;
$this->nodeChildID = $nodeChildID; // 0 means its parent node
Structure::$treeList[] = $this;
} else {
// idk perhaps throwing an error
}
}
public static function nodeExists($nodeID) {
if(is_array(Structure::$treeList)) {
foreach(Structure::$treeList as $key => $obj) {
if($obj->nodeID == $nodeID) return true;
}
}
return false;
}
public static function printTree() {
$parent = Structure::findParentNodes();
foreach($parent as $id => $obj) {
// So lets print all that node childs
echo "Rootnode: {$obj->nodeName}[ID : {$obj->nodeID}]
";
Structure::printChildNodes($obj->nodeID);
}
}
public static function findParentNodes() {
$countID = 0;
foreach(Structure::$treeList as $key => $obj)
if($obj->nodeChildID == 0) $parentNodes[$obj->nodeID] = $obj;
return $parentNodes;
}
public static function printChildNodes($nodeID) {
foreach(Structure::$treeList as $id => $obj) {
if($obj->nodeChildID == $nodeID) {
echo "Childnode : {$obj->nodeName}[ID : {$obj->nodeID}] (SubID : {$obj->nodeChildID})
";
//Structure::printChildNodes($nodeID);
}
}
}
}
$node2 = new Structure(4,"Links",0);
$node1 = new Structure(2,"Forum",0);
$node2 = new Structure(3,"Lol",2);
$node3 = new Structure(5,"SubSub",3);
Structure::printTree();
?>