PHP使用引用实现无限极分类
作者:互联网
PHP实现无限极分类
引用
<?php
public function buildTree($list, $pk='id', $pid='pid', $child='_child', $root=0){
$tree = array();
$packData = array();
foreach ($list as $data) {
$packData[$data[$pk]] = $data;
}
foreach ($packData as $key=>$val){
if($val[$pid] == $root){
$tree[] = &$packData[$key];
}else{
$packData[$val[$pid]][$child][] = &$packData[$key];
}
}
return $tree;
}
标签:packData,val,pid,tree,无限极,引用,key,PHP 来源: https://www.cnblogs.com/yulongcode/p/12825989.html