rendered paste body<?php# Simple Tree structureclass Structure { private static $treeList; // Holding our nodes private $nodeID, // like the name says $nodeName, // well da =D $nodeChildID, // huhh $nodeLevel; //mitmenda järgu nod public function Structure($nodeID, $nodeName, $nodeChildID, $nodeLevel) { if(!(Structure::nodeExists($nodeID))) { $this->nodeID = $nodeID; $this->nodeName = $nodeName; $this->nodeChildID = $nodeChildID; // 0 means its parent node $this->nodeLevel = $nodeLevel; 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: <b>{$obj->nodeName}</b>[ID : <b>{$obj->nodeID}</b>] <br>"; 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 : <b>{$obj->nodeName}</b>[ID : <b>{$obj->nodeID}</b>] (SubID : {$obj->nodeChildID})<br>"; $lapsed = Structure::kontrolli_lapsi($obj->nodeID); if($lapsed){ foreach($lapsed as $lapse_id){ echo ' --'; Structure::printNode($lapse_id); } } //Structure::printChildNodes($nodeID); } } echo '<br>'; } public static function asd(){ var_dump(Structure::$treeList); } public static function printNode($ID_p){ foreach(Structure::$treeList as $id => $obj) { if($obj->nodeID == $ID_p){ echo ' Noot: <b>'.($obj->nodeName).'</b>[ID : <b>'.($obj->nodeID).'</b>] (SubID : '.($obj->nodeChildID).')<br>'; } } } public static function kontrolli_lapsi($ID){ $lapsed = array(); foreach(Structure::$treeList as $id => $obj) { if($obj->nodeChildID == $ID){ array_push($lapsed, $obj->nodeID); } } return $lapsed; }}new Structure(1,"Esimene",0,0);new Structure(3,"esimese-nod1",1,1);new Structure(4,"esimese2-nod2",3,1);new Structure(5,"esimese2-nod3",3,1);new Structure(6,"esimese3-nod1",4,1);new Structure(7,"Teine",0,0);new Structure(8,"teise-nod1",7,1);Structure::printTree();Structure::asd();?>