PHP获取栏目的所有子级和孙级栏目的ID号示例
程序员文章站
2022-06-30 09:41:51
复制代码 代码如下: //@获取子栏目id号 private function soncategoryids($categoryid) { //@初始化栏目数组 $arra...
复制代码 代码如下:
//@获取子栏目id号
private function soncategoryids($categoryid)
{
//@初始化栏目数组
$array[] = $categoryid;
do
{
$ids = '';
$temp = $this->mysql->select('select `id` from `pcb_article_category` where `parentid` in (' . $categoryid . ')');
foreach ($temp as $v)
{
$array[] = $v['id'];
$ids .= ',' . $v['id'];
}
$ids = substr($ids, 1, strlen($ids));
$categoryid = $ids;
}
while (!empty($temp));
$ids = implode(',', $array);
return $ids;
}