无限极分类

    public function CategoryList(){
        $all_date = static::find()->asArray()->all();
        return $this->getTree($all_date, 0, 0);
    }

    public function getTree($date, $parent_id, $deep){
        static $ar = [];

        foreach($date as $key => $value){
            if($value['parent_id'] == $parent_id){
                $value['deep'] = $deep;
                $ar[] = $value;
                $this->getTree($date, $value['id'], $deep+1);
            }
        }

        return $ar;
    }

你可能感兴趣的:(php)