當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。