zoukankan      html  css  js  c++  java
  • 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;
        }

  • 相关阅读:
    python之函数嵌套与闭包
    python之高阶函数
    python之装饰器
    python之内置函数
    python之内置函数:map ,filter ,reduce总结
    Python之reduce函数
    install python2 python3 in same computer
    git basic
    git LF CRLF
    2 thread, first to open chat window, second to make the phone
  • 原文地址:https://www.cnblogs.com/xdingc/p/7545433.html
Copyright © 2011-2022 走看看