递归处理

/**
     * 获得子分类
     * @param $category
     * @param int $parent_id
     * @return array
     */
    public function getSonCategory($category, $parent_id=0){
        $arr  = array();
        foreach ($category as $key=>$value){
            if ($value['parent_id'] == $parent_id){
//                $arr[] = $value;
//                $this->getSonCategory($category,$value['category_id']);
                $value['son'] = $this->getSonCategory($category,$value['category_id']);
                $arr[] = $value;
            }
        }
        return $arr;
    }
posted @ 2020-09-11 08:39  胡良庆  阅读(140)  评论(0编辑  收藏  举报