aElements = array(); $this->result = array(); } /** * @desc add a node to the tree * @param integer, array, integer * @access public * @return void **/ public function addNode($iId, $sName, $iParentId = 0){ $this->aElements[$iParentId][] = array($iId, $sName); } /** * @desc add a subnode to the tree * @param integer, integer * @access private * @return void **/ private function addSubNode($iParentId, $iLevel){ if(isset($this->aElements[$iParentId])){ $iElements = count($this->aElements[$iParentId]); for($i = 0; $i < $iElements; $i++){ $this->result[] = $this->aElements[$iParentId][$i][1]; $this->addSubNode($this->aElements[$iParentId][$i][0], $iLevel+1); } } } /** * @desc return the array as an associative array * @param * @access public * @return array **/ public function getArray() { if(isset($this->aElements[0])) { $iElements = count($this->aElements[0]); for($i=0; $i < $iElements; $i++){ $this->result[] = $this->aElements[0][$i][1]; $this->addSubNode($this->aElements[0][$i][0], 1); } } return $this->result; } } ?>