All pastes #1090408 Raw Edit

Untitled

public php v1 · immutable
#1090408 ·published 2008-08-02 02:20 UTC
rendered paste body
<?php	class Channel {		private $id;		private $name;		private $parent;		private $childs = array();		public function __construct($id = 0, $name = '', Channel $parent = null){			$this->id = (int)$id;			$this->name = (string)$name;			$this->parent = $parent;			if($parent !== null){				$parent->addChild($this);			}		}		public function addChild(Channel $child){			$this->childs[] = $child;		}		public function getName(){			return $this->name;		}		public function getChilds(){			return $this->childs;		}	}   $a[0] = new Channel(0, 'main', null);	$a[1] = new Channel(1, 'chan 1', $a[0]);	$a[2] = new Channel(2, 'chan 2', $a[0]);	$a[3] = new Channel(3, 'sub chan 1', $a[1]);	$a[4] = new Channel(4, 'sub chan 2', $a[2]);	$a[5] = new Channel(5, 'sub sub chan 1', $a[3]);	function drawTree(Channel $a, $p){		$puce = '-'.$p;		printf("%s %s<br />", $puce, $a->getName());		$tabs = $a->getChilds();		foreach($tabs as $i => &$channel){			drawTree($channel, $puce);		}	}	drawTree($a[0], '>');?>