這篇文章主要介紹了PHP獲取欄目的所有子級和孫級欄目的ID號的具體實現,需要的朋友可以參考下
代碼如下: //@獲取子欄目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; }