无限递归分类,建一个父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;
}
网友评论