美文网首页
树状无限极分类

树状无限极分类

作者: peng_js | 来源:发表于2017-06-30 13:27 被阅读0次

    树状无限极分类 提供2种方式

    function getTree($list,$id=0,$level=0) {

               static $tree = array();

              foreach($list as $row) {

                  if($row['pid']==$id) {

                    $row['level'] = $level;

                    $row['name'] = str_repeat('----',$level). $row['name'];

                    $tree[] = $row;

                    $this->getTree($list, $row['id'], $level + 1);

                }

            }

        return $tree;

    }

    function getTree($list,$pid=0,$level=0) {

    static $tree = array();

    foreach($list as $row) {

    if($row['dept_pid']==$pid) {

    $row['dept_level'] = $level;

    $tree[] = $row;

    getTree($list, $row['dept_id'], $level + 1);

    }

    }

    return $tree;

    }

    相关文章

      网友评论

          本文标题:树状无限极分类

          本文链接:https://www.haomeiwen.com/subject/lknbcxtx.html