TP5.1无限极分类

这是无限极分类的实现,自己渲染视图即可ok

  public function index(){

              $index=DB::name('power')->select();
              $res=$this->digui($index);
              var_dump($res);
          }
        public function digui($arr,$path=0,$flag=1){
                    //定义空数组
                 static $data=array();
                 //循环遍历
                 foreach($arr as $key => $value){
                    //顶级id为0放进这个空数组中
                    if($value['parent_id']==$path){
                        $data[]=$value;
                        // var_dump($data);
                        //反之
                        $value['flag']=$flag;
                        $this->digui($arr,$value['p_id'],$flag+1);                    
                    }
                 }
                 return $data;
        }

你可能感兴趣的:(后台,tp)