Home > php教程 > php手册 > php 无限分类父子追溯方法

php 无限分类父子追溯方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:40:15
Original
1441 people have browsed it

php 无限分类之父级分类和子分类的追溯方法,代码片段如下:

Copy to Clipboard引用的内容:[www.bkjia.com] //返回所有的叶子节点
public function scanNodeOfTree($result,$fid){
$checkexist = false;
for ($i=0; $iif($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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template