递归

2018-11-13  本文已影响1人  F的平方

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);

上一篇 下一篇

猜你喜欢

热点阅读