[PHP] 纯文本查看 复制代码
/**
* 找出当前类的顶级分类id接口
*
* @param $categoryInfo 所有分类
* @param $nowCategory 当前分类
*
* @return 顶级分类id
*/
protected function _getTopCategory ($categoryInfo, $nowCategory)
{
if ( $nowCategory['pid'] != 0 ) {
foreach ( $categoryInfo as $cate ) {
if ( $cate['id'] == $nowCategory['pid'] ) {
if ( $cate['pid'] == 0) {
return $cate['id'];
} else {
$parentCate = [
'id' => $cate['id'],
'pid'=> $cate['pid']
];
return $this->_getTopCategory($categoryInfo, $parentCate);
}
}
}
} else {
return $nowCategory['id'];
}
}