无限极分类的递归写法

   /*
     * 遍历部门分类
     */
    public function index()
    {
        $Infomation = new Infomation;
        $select_datad = $Infomation -> show();
        $data = $this -> GetSortList($select_datad);
//        print_r($data);die;
        return $this -> fetch('show' , ['data' => $data]);
    }

    /*
     * 递归
     */
    protected function GetSortList($select_datad , $pid = 0,$level=''){
        static  $arr = array();
        foreach($select_datad as $val){
            if($val['dept_belong'] == $pid){
                if ($val['dept_belong'] == 0){
                    $level = '';
                }
                $val['level'] = $level;
                $arr[] = $val;
                $this->GetSortList($select_datad,$val['dept_id'],$level.'------');
            }
        }
        return $arr;
    }


缩进的时候是 . 拼接的

你可能感兴趣的:(无限极分类的递归写法)