通过分类列表产生分类树数组-PHP源码
php代码
// $list 为分类列表数组,键为分类 ID,值为分类节点对象,pid 为父分类 ID
$tree = array();
foreach ($list as $id => $row) {
$pid = $row->pid;
if ($pid == 0) {
$tree[] = &$list[$id];
} else if (isset($list[$pid])) {
$parent = &$list[$pid];
$parent->children[] = &$list[$id]; // 增加 children 属性标识子分类列表
}
}
/php/36609.htmlwww.phpzy.comtrue/php/36609.htmlTechArticle通过分类列表产生分类树数组-PHP源码 php代码 // $list 为分类列表数组,键为分类 ID,值为分类节点对象,pid 为父分类 ID$tree = array();foreach ($list as $id => $row) { $pid = $row->pid; if ($pid == 0) {...
PHP之友评论