求教无限分类的当前位置怎么写,顶者有分!!!
下面是一个无限分类的代码,想请问一下类中函数get_pos的使用方法,谢谢!!!
<br><?php <br />/**<br> +------------------------------------------------<br> * 通用的树型类<br> +------------------------------------------------<br> * @author [email protected]<br> +------------------------------------------------<br> * @date 2010年11月23日10:09:31<br> +------------------------------------------------<br> */<br>class Tree<br>{<br> <br> /**<br> +------------------------------------------------<br> * 生成树型结构所需要的2维数组<br> +------------------------------------------------<br> * @author [email protected]<br> +------------------------------------------------<br> * @var Array<br> */<br> var $arr = array();<br> <br> /**<br> +------------------------------------------------<br> * 生成树型结构所需修饰符号,可以换成图片<br> +------------------------------------------------<br> * @author [email protected]<br> +------------------------------------------------<br> * @var Array<br> */<br> var $icon = array('分隔','分隔一','分隔二');<br> <br> /**<br> * @access private<br> */<br> var $ret = '';<br> <br> /**<br> * 构造函数,初始化类<br> * @param array 2维数组,例如:<br> * array(<br> * 1 => array('id'=>'1','parentid'=>0,'name'=>'一级栏目一'),<br> * 2 => array('id'=>'2','parentid'=>0,'name'=>'一级栏目二'),<br> * 3 => array('id'=>'3','parentid'=>1,'name'=>'二级栏目一'),<br> * 4 => array('id'=>'4','parentid'=>1,'name'=>'二级栏目二'),<br> * 5 => array('id'=>'5','parentid'=>2,'name'=>'二级栏目三'),<br> * 6 => array('id'=>'6','parentid'=>3,'name'=>'三级栏目一'),<br> * 7 => array('id'=>'7','parentid'=>3,'name'=>'三级栏目二')<br> * )<br> */<br> function tree($arr=array())<br> {<br> $this->arr = $arr;<br> $this->ret = '';<br> return is_array($arr);<br> }<br> <br> /**<br> * 得到父级数组<br> * @param int<br> * @return array<br> */<br> function get_parent($myid)<br> {<br> $newarr = array();<br> if(!isset($this->arr[$myid])) return false;<br> $pid = $this->arr[$myid]['parentid'];<br> $pid = $this->arr[$pid]['parentid'];<br> if(is_array($this->arr))<br> {<br> foreach($this->arr as $id => $a)<br> {<br> if($a['parentid'] == $pid) $newarr[$id] = $a;<br> }<br> }<br> return $newarr;<br> }<br> <br> /**<br> * 得到子级数组<br> * @param int<br> * @return array<br> */<br> function get_child($myid)<br> {<br> $a = $newarr = array();<br> if(is_array($this->arr))<br> {<br> foreach($this->arr as $id => $a)<br> {<br> if($a['parentid'] == $myid) $newarr[$id] = $a;<br> }<div class="clear"> </div>