php 无限分类之父级分类和子分类的追溯方法,代码片段如下:
Copy to Clipboard引用的内容:
[www.bkjia.com]
//返回所有的叶子节点
public function scanNodeOfTree($result,$fid){
$checkexist = false;
for ($i=0; $i
if($fid == $result[$i]['ParentId']){
$checkexist = true;
$arr .= $this->scanNodeOfTree($result,$result[$i]['ID']).',';
}
}
if(!$checkexist){
return $fid;
}
return $arr;
}
//返回所有的上级节点
public function getNodeOfTree($result,$id,$arr){
if($id == 0){
return $arr;
}
foreach ($result as $items){
if($id == $items['ID']){
$arr[] = array($items['CateName'],$items['ID']);
$return = $this->getNodeOfTree($result,$items['ParentId'],$arr);
}
}
return $return;
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn