thinkphp递归无限极分类接口编写

无限递归分类,建一个父id的字段

/**
     * 获得子分类
     * @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;
    }

你可能感兴趣的:(thinkphp递归无限极分类接口编写)