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

PHP通过数据库的方式递归查询当前分类ID的所有子分类ID

时间:2022-12-23 23:33:37浏览次数:41  
标签:arr throws parent 分类 ID PHP id

/**
     * 通过数据库的方式递归查询当前分类ID的所有子分类ID
     * @param $id
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function findAllChild($id): array
    {
        static $arr = [];
        $members = self::where('pid', $id)->select()->toArray();
        foreach ($members as $member){
            $parent = $this->model->find($member['id'])->toArray();
            $arr[] = $parent;
            self::findAllChild($parent['id']);
        }
        return $arr;
    }

 

标签:arr,throws,parent,分类,ID,PHP,id
From: https://www.cnblogs.com/felixwan/p/17001837.html

相关文章