• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP tree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中tree函数的典型用法代码示例。如果您正苦于以下问题:PHP tree函数的具体用法?PHP tree怎么用?PHP tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了tree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: tree

function tree($array, $parent, $parts = array(), $step = 0)
{
    // echo "<pre>";
    //     print_r( $array );
    // echo "</pre>";
    // die();
    if (!count($array)) {
        return '';
    }
    $tid = $step == 0 ? 'id="tree"' : '';
    $t = '<ul class="list-unstyled" ' . $tid . '>';
    foreach ($array as $key => $item) {
        if (is_array($item)) {
            $open = $step !== false && (isset($parts[$step]) && $key == $parts[$step]);
            $t .= '<li class="directory' . ($open ? ' open' : '') . '" oncontextmenu="return false;">';
            $t .= '<a href="#" data-role="directory" id="' . preg_replace("/[^A-Za-z0-9]/", "", $key) . '" class="directory-name"><span class="glyphicon glyphicon-folder-' . ($open ? 'open' : 'close') . '"></span>' . $key . '</a>';
            $t .= tree($item, "{$parent}/{$key}", $parts, $open ? $step + 1 : false);
            $t .= '</li>';
        } else {
            $selected = isset($parts[$step]) && $item == $parts[$step];
            $t .= '<li class="file' . ($selected ? ' active' : '') . '"><a href="' . $parent . '/' . $item . '">' . $item . '</a></li>';
        }
    }
    $t .= '</ul>';
    return $t;
}
开发者ID:boutmos,项目名称:Wikitten,代码行数:26,代码来源:tree.php


示例2: tree

function tree($array, $parent, $parts = array(), $step = 0, $folder = "")
{
    if (!count($array)) {
        return '';
    }
    $tid = $step == 0 ? 'id="tree"' : '';
    $t = '<ul class="unstyled" ' . $tid . '>';
    foreach ($array as $key => $item) {
        if (is_array($item)) {
            $open = $step !== false && (isset($parts[$step]) && $key == $parts[$step]);
            $t .= '<li class="directory' . ($open ? ' open' : '') . '">';
            $t .= '<a href="#" data-role="directory"><i class="icon icon-folder-' . ($open ? 'open' : 'close') . '"></i> ' . $key . '</a>';
            $t .= tree($item, "{$parent}/{$key}", $parts, $open ? $step + 1 : false, $folder = $key);
            $folder = "";
            $t .= '</li>';
        } else {
            $selected = isset($parts[$step]) && $item == $parts[$step];
            if ($folder != "") {
                $folder = $folder . "/";
            }
            $t .= '<li class="file' . ($selected ? ' active' : '') . '"><a href="' . PLUGPATH . urlencode($folder . $item) . '">' . $item . '</a></li>';
        }
    }
    $t .= '</ul>';
    return $t;
}
开发者ID:hersche,项目名称:Peta,代码行数:26,代码来源:tree.php


示例3: get_categories

 private function get_categories()
 {
     $categories = Cache::rememberForever('wyshop_admin_category_categories', function () {
         $categories = Category::orderBy('parent_id', 'asc')->orderBy('sort_order', 'asc')->orderBy('id', 'asc')->get();
         return tree($categories);
     });
     return $categories;
 }
开发者ID:beidouzhiguang,项目名称:wy_shop,代码行数:8,代码来源:GoodController.php


示例4: tree

function tree($data, $i = 0, &$result = array())
{
    $result[$i] = [];
    if (array_key_exists($i, $data)) {
        foreach ($data[$i] as $value) {
            tree($data, $value, $result[$i]);
        }
    }
}
开发者ID:urazov,项目名称:tree,代码行数:9,代码来源:index.php


示例5: tree

function tree($parent)
{
    $d = "<li><a href='?Id=" . $parent->getId() . "'>" . $parent->getName() . "</a>";
    foreach ($parent->getZones() as $zone) {
        $d .= "<ul>";
        $d .= tree($zone);
        $d .= "</ul>";
    }
    return $d . "</li>";
}
开发者ID:googlecode-mirror,项目名称:blksqltree,代码行数:10,代码来源:Example.php


示例6: tree

 public static function tree($data, $pid = 0, $depth = 0, &$tree = array())
 {
     foreach ($data as $key => $val) {
         if ($pid == $val['pid']) {
             $val['depth'] = $depth;
             $tree[] = $val;
             tree($data, $val['id'], $depth + 1, $tree);
         }
     }
     return $tree;
 }
开发者ID:BGCX262,项目名称:zshop-zendframework-svn-to-git,代码行数:11,代码来源:common.php


示例7: tree

function tree(&$data, $parent_id = 0, $count = 1)
{
    static $result = array();
    foreach ($data as $key => $value) {
        if ($value['parent_id'] == $parent_id) {
            $value['count'] = $count;
            $result[] = $value;
            unset($data[$key]);
            tree($data, $value['id'], $count + 1);
        }
    }
    return $result;
}
开发者ID:beidouzhiguang,项目名称:wy_shop,代码行数:13,代码来源:helpers.php


示例8: tree

function tree($dir, $exclude)
{
    $dirs = preg_grep('/^([^.])/', array_diff(scandir($dir), $exclude));
    $tree = array();
    foreach ($dirs as $current) {
        if (is_dir($dir . "/" . $current)) {
            $tree[$current] = tree($dir . "/" . $current, $exclude);
        } else {
            $tree[$current] = $current;
        }
    }
    return $tree;
}
开发者ID:arnaudjuracek,项目名称:www-hello,代码行数:13,代码来源:cms.php


示例9: tree

function tree($tree)
{
    foreach ($tree as $value) {
        echo "<li><a href=\"javascript:delService('" . $value['id'] . "','" . $value['name_cn'] . "');\" class='delSub'>删除</a>";
        echo "<a href='" . ROOT_URL . "service/update?id=" . $value['id'] . "'>更改</a>";
        echo "<a href='" . ROOT_URL . "service/create?pid=" . $value['id'] . "'>增加子节点</a>";
        echo "<a href='" . ROOT_URL . "service/detail?id=" . $value['id'] . "'>查看</a>";
        echo "<span style='margin-left:" . (string) ($value['depth'] * 30) . "px'>" . $value['name_cn'] . "</span><input type='hidden' class='catid' value='" . $value['id'] . "'></li>";
        if ($value['children'] != null) {
            tree($value['children']);
        }
    }
}
开发者ID:puppylsy,项目名称:pmsadmin,代码行数:13,代码来源:index.php


示例10: tree

function tree(&$list, $pid = 0, $level = 0, $html = '<lable class="label label-info">|----</lable>')
{
    static $tree = array();
    foreach ($list as $v) {
        if ($v['pid'] == $pid) {
            $v['sort'] = $level;
            $v['html'] = str_repeat($html, $level);
            $tree[] = $v;
            tree($list, $v['id'], $level + 1);
        }
    }
    return $tree;
}
开发者ID:mracale,项目名称:agent,代码行数:13,代码来源:function.php


示例11: tree

function tree($tree)
{
    foreach ($tree as $value) {
        echo "<li><a href=\"javascript:delPractice('" . $value['id'] . "','" . $value['name_cn'] . "');\" class='delSub'>delete</a>";
        echo "<a href='" . ROOT_URL . "practice/update?lang=en&id=" . $value['id'] . "'>update</a>";
        echo "<a href='" . ROOT_URL . "practice/create?lang=en&pid=" . $value['id'] . "'>create child node</a>";
        echo "<a href='" . ROOT_URL . "practice/detail?lang=en&id=" . $value['id'] . "'>view</a>";
        echo "<span style='margin-left:" . (string) ($value['depth'] * 30) . "px'>" . $value['name_en'] . "</span><input type='hidden' class='catid' value='" . $value['id'] . "'></li>";
        if ($value['children'] != null) {
            tree($value['children']);
        }
    }
}
开发者ID:puppylsy,项目名称:pmsadmin,代码行数:13,代码来源:index_en.php


示例12: tree

/**
 *  无线分类的树形简单实现
 * @param type $list
 * @param type $pid_key  父字段名
 * @param type $id_key   主键名
 * @param type $pid
 * @param type $level
 * @param type $html
 * @return type
 */
function tree($list, $pid_key = 'pid', $id_key = 'id', $pid = 0, $level = 0, $html = '----')
{
    $tree = array();
    foreach ($list as $v) {
        if ($v[$pid_key] == $pid) {
            $v['sort'] = $level;
            $v['html'] = str_repeat($html, $level);
            $tree[] = $v;
            $tree = array_merge($tree, tree($list, $pid_key, $id_key, $v[$id_key], $level + 1, $html));
        }
    }
    return $tree;
}
开发者ID:visonforcoding,项目名称:cidev,代码行数:23,代码来源:app_helper.php


示例13: tree

/**
 * Output a microdata object representation as tree
 * 
 * @param \stdClass $object			Object
 * @param \boolean $link			Link values
 * @return \string					HTML
 */
function tree($object, $link = false)
{
    $html = '';
    // If it's a true object
    if ($object instanceof \stdClass) {
        // If it's a micro information item
        if (property_exists($object, 'types') && property_exists($object, 'id') && property_exists($object, 'value') && property_exists($object, 'properties')) {
            $html .= '<h3><span class="item-type">' . implode('</span> + <span class="item-type">', array_map('htmlspecialchars', $object->types)) . '</span> <span class="item-id">[ID = ' . htmlspecialchars($object->id ? $object->id : 'NULL') . ']</span></h3>';
            if (strlen($object->value)) {
                $html .= '<div class="item-value">' . htmlspecialchars($object->value) . '</div>';
            }
            if (count($object->properties)) {
                $html .= '<dl class="item-properties">';
                foreach ($object->properties as $property => $values) {
                    $html .= '<dt>' . htmlspecialchars($property) . '</dt>';
                    $html .= '<dd>' . tree($values, in_array($property, \Jkphl\Micrometa\Item::$urlProperties)) . '</dd>';
                }
                $html .= '</dl>';
            }
            if (count($object->children)) {
                $html .= '<dl class="item-children">';
                $html .= '<dt>children</dt>';
                $html .= '<dd>' . tree($object->children, false) . '</dd>';
                $html .= '</dl>';
            }
        } else {
            $html .= '<dl class="object">';
            foreach (get_object_vars($object) as $property => $values) {
                $html .= '<dt>' . htmlspecialchars($property) . '</dt>';
                $html .= '<dd>' . tree($values, $link || in_array($property, array_merge(\Jkphl\Micrometa\Item::$urlProperties, array('rels')))) . '</dd>';
            }
            $html .= '</dl>';
        }
        // Else: If it's an (ordered) list
    } elseif (is_array($object)) {
        $html .= '<ol>';
        foreach ($object as $value) {
            $value = tree($value, $link || in_array($value, array('rels')));
            $html .= '<li>' . ($link ? '<a href="' . $value . '" target="_blank">' . $value . '</a>' : $value) . '</li>';
        }
        $html .= '</ol>';
        // Else: If it's an empty value
    } elseif (!strlen($object)) {
        $html .= '—';
        // Else: It's a scalar
    } else {
        $html .= htmlspecialchars($object);
    }
    return $html;
}
开发者ID:jkphl,项目名称:micrometa,代码行数:57,代码来源:micrometa.php


示例14: tree

function tree($directory)
{
    $mydir = dir($directory);
    echo "<ul>\n";
    while ($file = $mydir->read()) {
        if (is_dir("{$directory}/{$file}") and $file != "." and $file != "..") {
            echo "<li><font color=\"#ff00cc\"><b>{$file}</b></font></li>\n";
            tree("{$directory}/{$file}");
        } else {
            echo "<li>{$file}</li>\n";
        }
    }
    echo "</ul>\n";
    $mydir->close();
}
开发者ID:lyhiving,项目名称:icampus,代码行数:15,代码来源:filelist.php


示例15: tree

function tree($dir = '.', $files = true)
{
    if (!isset($dossiers[0]) || $dossiers[0] != $dir) {
        $dossiers[0] = $dir;
    }
    if (!is_dir($dir) && $files) {
        return array($dir);
    } elseif (!is_dir($dir) && !$files) {
        return array();
    }
    $list = _glob(addslash_if_needed($dir));
    foreach ($list as $dossier) {
        $dossiers = array_merge($dossiers, tree($dossier, $files));
    }
    return $dossiers;
}
开发者ID:eauland,项目名称:ShareMe,代码行数:16,代码来源:core.php


示例16: tree

/**
 * Created an nested unordered list from a multidimensional array
 *
 * @param  array
 * @return string
 */
function tree(array $nodes, Closure $render = null)
{
    $output = '<ul class="no-bullet">';
    foreach ($nodes as $node) {
        // Get name
        $name = is_null($render) ? $node['name'] : $render($node);
        // Render node
        $output .= '<li>' . $name;
        // Render children
        if ($node['children']) {
            $output .= tree($node['children'], $render);
        }
        $output .= '</li>';
    }
    return $output . '</ul>';
}
开发者ID:LeandrosilvaDG,项目名称:Wiki,代码行数:22,代码来源:helpers.php


示例17: tree

function tree($array, $parentId = 0, $level = 0, $symbol = '-')
{
    $data = array();
    foreach ($array as $value) {
        if ($value['parent_id'] == $parentId) {
            if ($parentId != 0) {
                $value['html'] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level);
                $value['html'] .= '|';
                $value['html'] .= str_repeat($symbol, $level);
            }
            $sub = tree($array, $value['id'], $level + 1);
            $data[] = $value;
            $data = array_merge($data, $sub);
        }
    }
    return $data;
}
开发者ID:dxkrs,项目名称:RaysonLuBlog,代码行数:17,代码来源:function.php


示例18: display_tree

function display_tree($array)
{
    $root = NULL;
    foreach ($array as $child) {
        if ($child['lft'] == '1') {
            $root = 'class="ignore"';
        }
        echo "<li {$root} id=\"" . $child['lft'] . "\">\n";
        echo "<div class=\"item\">" . $child['lft'] . ' : ' . $child['title'] . ' : ' . $child['rgt'] . anchor('delete', 'Delete') . " " . anchor('edit', 'Edit') . " " . anchor('move', 'Move', 'class="drop"') . "</div>";
        if (isset($child['children'])) {
            echo "<ul class=\"pagetree\">\n";
            tree($child['children']);
            echo "</ul>\n";
        }
        echo "\t</li>\n";
    }
}
开发者ID:acutedeveloper,项目名称:openreach-connected-ci,代码行数:17,代码来源:demo.php


示例19: tree

function tree($items)
{
    echo '<ul>';
    foreach ($items as $item) {
        $url1 = URL::site('category/edit?id=' . $item['id']);
        $url2 = URL::site('category/add?pid=' . $item['id']);
        echo '<li><span>' . $item['name'] . '</span>';
        echo '<div class="pull-right" style="margin-top: 10px;_display: none">';
        echo '<a href="' . $url1 . '" class="btn btn-info btn-xs ajax-click _ajax-modal-sm">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;';
        echo '<a href="' . $url2 . '" class="btn btn-info btn-xs ajax-click _ajax-modal-sm">+子类</a></div>';
        if (isset($item['children']) && is_array($item['children'])) {
            tree($item['children']);
        }
        echo '</li>';
    }
    echo '</ul>';
}
开发者ID:andygoo,项目名称:admin,代码行数:17,代码来源:category_tree.php


示例20: tree

function tree($path, $n = 0)
{
    foreach (scandir($path) as $name) {
        if (canStop($n)) {
            return;
        }
        if ('.' === $name || '..' === $name) {
            continue;
        }
        $f = $path . DIRECTORY_SEPARATOR . $name;
        if (is_dir($f)) {
            displayDir($name, $n);
            tree($f, $n + 1);
        } else {
            displayFile($name, $n);
        }
    }
}
开发者ID:quorzz,项目名称:handy-tools,代码行数:18,代码来源:tree.php



注:本文中的tree函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP treeSelectInput函数代码示例发布时间:2022-05-23
下一篇:
PHP trcategory函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap