All pastes #944703 Raw Edit

Something

public php v1 · immutable
·published 2008-03-16 10:25 UTC
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		public function Structure($nodeID, $nodeName, $nodeChildID) {		if(!(Structure::nodeExists($nodeID))) {			$this->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: <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>";				//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();?>