复制代码 代码如下:

array(‘id’=>’1′,’parentid’=>0,’name’=>’拔尖栏面生龙活虎’), * 2 =>
array(‘id’=>’2′,’parentid’=>0,’name’=>’一级栏目二’), * 3 =>
array(‘id’=>’3′,’parentid’=>1,’name’=>’二级栏目风流洒脱’), * 4 =>
array(‘id’=>’4′,’parentid’=>1,’name’=>’二级栏目二’), * 5 =>
array(‘id’=>’5′,’parentid’=>2,’name’=>’二级栏目三’), * 6 =>
array(‘id’=>’6′,’parentid’=>3,’name’=>’三级栏目风姿洒脱’), * 7 =>
array(‘id’=>’7′,’parentid’=>3,’name’=>’三级栏目二’) * ) */
function tree { $this->arr = $arr; $this->ret = ”; return
is_array; } /** * 拿到父级数组 * @param int * @return array */
function get_parent { $newarr = array(); if(!isset return false; $pid =
$this->arr[$myid][‘parentid’]; $pid =
$this->arr[$pid][‘parentid’]; if { foreach($this->arr as $id
=> $a) { if($a[‘parentid’] == $pid) $newarr[$id] = $a; } } return
$newarr; } /** * 获得子级数组 * @param int * @return array */
function get_child { $a = $newarr = array(); if { foreach($this->arr
as $id => $a) { if($a[‘parentid’] == $myid) $newarr[$id] = $a; }
} return $newarr ? $newarr : false; } /** * 获得当前职分数组 *
@param int * @return array */ function get_pos { $a = array();
if(!isset return false; $newarr[] = $this->arr[$myid]; $pid =
$this->arr[$myid][‘parentid’]; if(isset { $this->get_pos; }
if { krsort; foreach { $a[$v[‘id’]] = $v; } } return $a; } /** *
————————————- * 获得树型结构 *
————————————- * @author Midnight,
yangyunzhou@foxmail.com * @param $myid 代表收获那几个ID下的具备子级 *永利皇宫
@param $str 生成树形结构基本代码, 比如: “\$spacer\$name” * @param
$sid 被选中的ID, 举例在做树形下拉框的时候要求用到 * @param $adds *
@param $str_group * @return unknown_type */ function
get_tree($myid, $str, $sid = 0, $adds = ”, $str_group = ”) {
$number=1; $child = $this->get_child; if { $total = count; foreach {
$j=$k=”; if { $j .= $this->icon[2]; } else { $j .=
$this->icon[1]; $k = $adds ? $this->icon[0] : ”; } $spacer =
$adds ? $adds.$j : ”; $selected = $id==$sid ? ‘selected’ : ”;
@extract; $parentid == 0 && $str_group ? eval(“\$nstr =
\”$str_group\”;”) : eval; $this->ret .= $nstr;
$this->get_tree($id, $str, $sid, $adds.$k.”,$str_group);
$number++; } } return $this->ret; } /** *
同上一方法相近,但允大多选 */ function get_tree_multi($myid, $str,
$sid = 0, $adds = ”) { $number=1; $child = $this->get_child; if {
$total = count; foreach { $j=$k=”; if { $j .= $this->icon[2]; }
else { $j .= $this->icon[1]; $k = $adds ? $this->icon[0] : ”;
} $spacer = $adds ? $adds.$j : ”; $selected = $this->have ?
‘selected’ : ”; //echo $sid.’=>’.$id.’ : ‘.$selected.’ .
‘; @extract; eval; $this->ret .= $nstr;
$this->get_tree_multi($id, $str, $sid, $adds.$k.”); $number++; } }
return $this->ret; } function have{
return(strpos(‘,,’.$list.’,’,’,’.$item.’,’)); }}?>

网站地图xml地图