PHP通过数据库的方式递归查询当前分类ID的所有子分类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 = self::find($member['id'])->toArray(); $arr[] = $parent; self::findAllChild($parent['id']); } return $arr; }