当前位置: 首页>>代码示例>>PHP>>正文


PHP tree函数代码示例

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


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


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