Home >Backend Development >PHP Tutorial >Generate infinitely classified structures

Generate infinitely classified structures

巴扎黑
巴扎黑Original
2016-11-22 09:12:131203browse

生成无限分类的结构

public function get_tree_1(array $list = array())
{
$root = array();
$node = array();

foreach ($list as $k => $v) {

list($id, $pid, $name, $path) = array_values($v);
$node[$id] = $v;

if(isset($node[$pid])) {
$node[$pid]['child'][$id] = &$node[$id];
}

if($pid == 0) {
$root[$id] = &$node[$id];
}

}

return $root;
}


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