php按层数获取无限极分类

/获取一个id下的所有节点下级
 /**
 * [addbonus 增加动态奖金表]
 * @param  [type] $var       [会员id]
 * @param  [type] $level 	 [层数]
 * @param  [type] $type      [最大层数,默认最大层]
 * @return [type] array      [所有下线的数组]
 */
 function getsort($var,$level=1,$type=0){
    
    global $temp;
    $zctjuser = M('member')->where(array('p_id' => $var,'delete'=>0))->select();
    $data = array();
    foreach ($zctjuser as $value) {
        $data[]=$value;
    }
    if(!empty($data)){
        foreach ($data as $key => $value) {
            $temp[]=$value;
            if($type == 0 || $level < $type){
            	getsort($value['id'],$level+1,$type);
            }
        }
    }
    return $temp;
 }

你可能感兴趣的:(php,工具代码)