php 无限极分类

//无限极分类  展示
function getree($arr,$pid,$step){
	global $tree;
	foreach ($arr as $key => $value) {
		if ($value['pid']==$pid) {
			$temp=str_repeat('└―', $step);
			$value['name']=$temp.$value['name'];
			$tree[]=$value;
			getree($arr,$value['cid'],$step+1);
		}
	}
	return $tree;
}
//子集  child
function getTree1($arr, $pid,$level){
    $tree = '';
    foreach($arr as $k => $v){
      $v['level']=$level;
      if($v['pid'] == $pid){//父亲找到儿子
       $v['child'] = getTree1($arr, $v['cid'],$level+1);
       $tree[] = $v;
       //unset($data[$k]);
      }
    }
    return $tree;
}

  

posted @ 2018-05-10 17:40  zhuzhipeng  阅读(222)  评论(0编辑  收藏  举报