凌的博客

您现在的位置是:首页  > 学无止境 > PHP

PHP

php无限级子类调用

2015-04-25PHP0
/** 获取分类所有子级 */ function get_child_cat($catid,$field=\'id,pid,name\',$order=\'listorder asc\',&$level=0){ $max_level = 5; // 最大递归等级 $cate = D()->field($field)->from(\'catetorys
/**
 获取分类所有子级
*/
function get_child_cat($catid,$field='id,pid,name',$order='listorder asc',&$level=0){
	$max_level = 5; // 最大递归等级
	$cate = D()->field($field)->from('catetorys')->where(" pid in ( '". $catid."' )")->order($order)->select();
	$cates = array();
	if(!empty($cate)){
		if($level++ > $max_level){
			return $cates;	
		}
		foreach($cate as $k=>$v){
			$v['child'] = get_child_cat($v['id'],$field,$order,$level);
			$cates[] = $v;
		}	
		return $cates;
	}
}

如果本文对您有所帮助,请支持下本站哦!!!^_^

文章评论

0条评论