parent数组成等级菜单全展开式顺序排列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了parent数组成等级菜单全展开式顺序排列相关的知识,希望对你有一定的参考价值。
public function buildM($data,$parent=0){//分级数组
$tree=array();
foreach ($data as $node){
if($node["parent"]==$parent){
$children = $this->buildM($data,$node[‘id‘]);
if($children){
$node["children"] = $children;
}
$tree[] = $node;
}
}
return $tree;
}
public function buildN($data){//展开分级数组
foreach ($data as $node){
if(isset($node[‘children‘])){
$children = $node[‘children‘];
unset($node[‘children‘]);
$tree[] = $node;
$tree = array_merge($tree,$this->buildN($children));
}else {
$tree[] = $node;
}
}
return $tree;
}
以上是关于parent数组成等级菜单全展开式顺序排列的主要内容,如果未能解决你的问题,请参考以下文章