首页 > 数据库 >PHP通过数据库递归的方式查找当前分类ID的所有上级ID

PHP通过数据库递归的方式查找当前分类ID的所有上级ID

时间:2022-12-23 23:22:31浏览次数:41  
标签:info throws uid 递归 ids ID PHP id

/**
     * 通过数据库递归的方式查找当前分类ID的所有上级ID
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws DataNotFoundException
     */
    public function findAllParents($uid, $id): array
    {
        static $ids = [];
        $info = Db::name('表')->where('uid', $uid)->where('id', $id)->find();
        if (!empty($info)) {
            $ids[] = $info['id'];
            $this->findAllParents($uid, $info['pid']);
        }
        return $ids;
    }

 

标签:info,throws,uid,递归,ids,ID,PHP,id
From: https://www.cnblogs.com/felixwan/p/17001823.html

相关文章