獲取分類演算法
阿新 • • 發佈:2018-11-30
/**
* 獲取所有下級分類(包含本身)
*/
public function getAllLowerCategory($pid = 0){
$category = ProductCategory::select('pc_id')->where('pc_parent_id',$pid)->get()->toArray();
if(!in_array($pid,self::$lower_category)){
//新增自身
self::$lower_category[] = $pid;
}
if(!empty($category)){
foreach($category as $k => $v){
self::$lower_category[] = $v['pc_id'];
$this->getAllLowerCategory($v['pc_id']);
}
}
return self::$lower_category;
}
資料結構如下:
[0,"22c87a8ed3ede665da618fec107f6c07",
"3b37669405b484cd026d68c984044d0f","604bab2a4774d2c9cc55db134151456f",
"45e71495dc1cd9dae87b3a44c693c908",