class Query extends Controller{
//有个中间缓冲区,声明成静态数组!
private static $dep_buffer = [];
//递归获取部门集合中父id是$depid的所有部门
private function getChildDepid($depid,&$departments){
foreach($departments as $index => $dep){
if($dep['parentid']==$id){
if($dep[isFater']==1){
self::$nextCom++;
}
//剔除 下次不再有 优化~
unset($departments[$index]);
self::$dep_buffer[$index] = $dep;
$this -> getChildDepid($dep['id'],$departments);
}
}
return self::$dep_buffer;
}
}
调用递归方法之前,重置静态数组
self::$dep_buffer = [];
$departmentList[$index]['nextDeps'] = $this -> getChildDepid($top_company['id'],$departments);
网友评论