递归无限查询上级或者下级

Posted junyi-bk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了递归无限查询上级或者下级相关的知识,希望对你有一定的参考价值。

   $this->get_array($user[‘uid‘],1);

    function get_array($user_id,$top=0)
        $sql = ‘SELECT * FROM  ‘ . tablename(‘weixinmao_house_userinfo‘).‘where pid=:pid‘;
        $params = array(‘:pid‘ => $user_id);
        $rows = pdo_fetchall($sql, $params);
        foreach ($rows as $key=>$value)
        
            $r = $this->get_array($value[‘uid‘]); //调用函数,传入参数,继续查询下级
            $arr[0][‘children‘][$key][‘uid‘]= $value[‘uid‘]; //组合数组
            $arr[0][‘children‘][$key][‘wechaname‘]= $value[‘wechaname‘]; //组合数组
            if(is_array($r))
                $arr[0][‘children‘][$key][‘children‘]= $r[0][‘children‘];
            

        
        return $arr;
    

 

以上是关于递归无限查询上级或者下级的主要内容,如果未能解决你的问题,请参考以下文章