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;
}