数据表结构
//递归 - 获取当前分类下的所有子集id
public function test(){
$child = $this->getAllNextId(4);
p($child);exit;
}
public function getAllNextId($id,$data=[]){ $pids = DB::name(‘Category‘)->where(‘pid‘,$id)->column(‘id‘); if(count($pids)>0){ foreach($pids as $v){ $data[] = $v; $data = $this->getAllNextId($v,$data); //注意写$data 返回给上级 } } if(count($data)>0){ return $data; }else{ return false; } }