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


PHP printTree函数代码示例

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


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

示例1: printTree

function printTree($level = 1)
{
    // Открываем каталог и выходим в случае ошибки.
    $d = @opendir(".");
    if (!$d) {
        return;
    }
    while (($e = readdir($d)) !== false) {
        // Игнорируем элементы .. и .
        if ($e == '.' || $e == '..') {
            continue;
        }
        // Нам нужны только подкаталоги.
        if (!@is_dir($e)) {
            continue;
        }
        // Печатаем пробелы, чтобы сместить вывод.
        for ($i = 0; $i < $level; $i++) {
            echo "  ";
        }
        // Выводим текущий элемент.
        echo "{$e}\n";
        // Входим в текущий подкаталог и печатаем его
        if (!chdir($e)) {
            continue;
        }
        printTree($level + 1);
        // Возвращаемся назад
        chdir("..");
        // Отправляем данные в браузер, чтобы избежать видимости зависания
        // для больших распечаток.
        flush();
    }
    closedir($d);
}
开发者ID:igorsimdyanov,项目名称:php7,代码行数:35,代码来源:tree.php

示例2: HandleViewSite

function HandleViewSite()
{
    define("CMD_SEL_ITEMSCOUNT", <<<SQL
\t\tSELECT count(*) FROM items
\t\t\tWHERE category_id = ? AND our_category_id = 0
\t\t\tORDER BY status DESC, mdate DESC
SQL
);
    define("CMD_SEL_SITECATEGORIES", <<<SQL
\t\tSELECT * FROM site_categories
\t\t\tWHERE site_id = ? AND our_category_id = 0
SQL
);
    global $db;
    $res =& $db->query(CMD_SEL_SITECATEGORIES, array($_REQUEST["siteId"]));
    if (PEAR::isError($res)) {
        printError($res);
        exit;
    }
    $categories = array();
    while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
        $catCount =& $db->getOne(CMD_SEL_ITEMSCOUNT, array($row->id));
        if (PEAR::isError($catCount)) {
            $catCount = 0;
        }
        $state = null;
        if ((int) $catCount > 0) {
            $state = "collapsed";
        }
        $customAttrs = array("siteId" => $_REQUEST["siteId"]);
        $categories[] = array("nodeId" => $row->id, "name" => $row->name, "state" => $state, "tp" => NODE_SITE_CATEGORY, "image" => getCategoryImageState($row), "customAttrs" => $customAttrs);
    }
    printTree($categories, true, true, "TreeCategories");
    print "<span id=\"siteId\" siteIdNum=\"" . $_REQUEST["siteId"] . "\" style=\"display: none;\"></span>";
}
开发者ID:rivetweb,项目名称:old-auto-catalog,代码行数:35,代码来源:HandleViewSite.php

示例3: test_printTree

 public function test_printTree()
 {
     $actual = '<li><a rel=site >site</a></li><li><h2>slug</h2><ul><li><a rel=0 >0</a></li><li><a rel=1 >1</a></li></ul></li><li><h2>query</h2><ul><li><a rel=comp >comp</a></li><li><a rel=category >category</a></li></ul></li>';
     $testArray = array('site' => 'dummy', 'slug' => array(0 => 'testkit', 1 => ''), 'query' => array('comp' => 'testcase', 'category' => '22ffa003527fc7b4cfddb491cbfb1804'));
     $result = printTree($testArray);
     //echo $result;
     $this->assertEquals($actual, $result);
 }
开发者ID:logiks,项目名称:logiks-core,代码行数:8,代码来源:test_helpers_listarray.php

示例4: deletes

function deletes($nestedSet, $deletes)
{
    foreach ($deletes as $delete) {
        $row = br()->db()->getRow('SELECT * FROM br_nested_set WHERE name = ?', $delete);
        br()->db()->table('br_nested_set')->remove($row['id']);
        $nestedSet->processDelete($row);
        printTree();
        $nestedSet->verify();
    }
}
开发者ID:jagermesh,项目名称:bright,代码行数:10,代码来源:BrNestedSet.php

示例5: printTree

function printTree($tree)
{
    if (!is_null($tree) && count($tree) > 0) {
        echo '<ul>';
        foreach ($tree as $node) {
            $dep_id = $node['name'][0];
            echo '<li onclick=\'display_info(' . $dep_id . ')\'>' . $node['name'][1];
            printTree($node['children']);
            echo '</li>';
        }
        echo '</ul>';
    }
}
开发者ID:anurag95,项目名称:SpinLogics,代码行数:13,代码来源:categories.php

示例6: printTree

function printTree($tree, $r = 0, $p = null)
{
    foreach ($tree as $i => $t) {
        $dash = $t['parent'] == 0 ? '' : str_repeat('-', $r) . ' ';
        printf("\t<option value='%d'>%s%s</option>\n", $t['id'], $dash, $t['name']);
        if ($t['parent'] == $p) {
            // reset $r
            $r = 0;
        }
        if (isset($t['_children'])) {
            printTree($t['_children'], ++$r, $t['parent']);
        }
    }
}
开发者ID:atonevbg,项目名称:snippets,代码行数:14,代码来源:snippets2.php

示例7: printTree

function printTree($tree, $r = 0, $p = null, $id)
{
    foreach ($tree as $i => $t) {
        $dash = $t->parent_id == 0 ? '' : str_repeat('----', $r) . ' ';
        $selected = $t->id == $id ? 'selected' : '';
        print "\t<option " . $selected . " value='" . $t->id . "'>" . $dash . $t->name . "</option>\n";
        if ($t->parent_id == $p) {
            //reset $r
            $r = 0;
        }
        if (isset($t->_children)) {
            $j = printTree($t->_children, $r + 1, $t->parent_id, $id);
        }
    }
    return $j;
}
开发者ID:ariborneo,项目名称:koperasi,代码行数:16,代码来源:tree_helper.php

示例8: printTree

function printTree($node, $indent, $prefix)
{
    $indentStr = "    ";
    $printStr = "";
    for ($i = 0; $i < $indent; $i++) {
        $printStr = $printStr . $indentStr;
    }
    echo $printStr . $prefix . " value: " . $node->data . "\n";
    $indent++;
    if ($node->left) {
        printTree($node->left, $indent, "left: ");
    }
    if ($node->right) {
        printTree($node->right, $indent, "right: ");
    }
}
开发者ID:bobbybouwmann,项目名称:ap-algorithms-bst,代码行数:16,代码来源:index.php

示例9: printTree

/**
 * Построение дерева
 */
function printTree($tree, $printUL = true, $isRoot = false, $name = "")
{
    if ($isRoot) {
        print '<ul id="' . $name . '" class="tree">';
    } else {
        if ($printUL) {
            print '<ul>';
        }
    }
    foreach ($tree as $item) {
        $img = "";
        $childsCode = "";
        // Имеются дочерние узлы
        if (isset($item["childs"]) && sizeof($item["childs"]) > 0) {
            $img = "collapsed";
            $childsCode = printTree($item["childs"]);
        } else {
            $img = "leaf";
        }
        if (isset($item["state"])) {
            $img = $item["state"];
        }
        $nodeType = isset($item["tp"]) ? " tp='" . $item["tp"] . "'" : "";
        $customImg = "";
        if (isset($item["image"])) {
            $imgAlt = "alt='" . basename($item["image"], ".png") . "'";
            $customImg = "<img src='" . $item["image"] . "' {$imgAlt}>";
        }
        $customAttrsCode = " ";
        if (isset($item["customAttrs"])) {
            $customAttrs = $item["customAttrs"];
            foreach ($customAttrs as $k => $v) {
                $customAttrsCode .= "{$k}=\"{$v}\" ";
            }
        }
        $liClass = isset($item["liClass"]) ? "class='" . $item["liClass"] . "'" : "";
        print "<li {$liClass}><img src='" . sprintf(TREE_IMAGE_MASK, $img) . "'>" . "<span nodeId='" . $item["nodeId"] . "'" . $nodeType . $customAttrsCode . ">" . $customImg . $item["name"] . "</span>" . $childsCode . "</li>";
    }
    if ($printUL) {
        print '</ul>';
    }
}
开发者ID:rivetweb,项目名称:old-auto-catalog,代码行数:45,代码来源:Misc.php

示例10: printTree

 function printTree($arr, $format = "ul,li,h2,a")
 {
     if (!is_array($format)) {
         $format = explode(",", $format);
     }
     for ($i = sizeOf($format); $i <= 4; $i++) {
         array_push($format, "span");
     }
     $s = "";
     foreach ($arr as $a => $b) {
         if (is_array($b)) {
             $s .= "<{$format[1]}><{$format[2]}>{$a}</{$format[2]}>";
             $s .= "<{$format[0]}>" . printTree($b, $format) . "</{$format[0]}>";
             $s .= "</{$format[1]}>";
         } else {
             $s .= "<{$format[1]}><{$format[3]} rel={$a} >{$a}</{$format[3]}></{$format[1]}>";
         }
     }
     return $s;
 }
开发者ID:logiks,项目名称:logiks-core,代码行数:20,代码来源:listarray.php

示例11: printTree

function printTree($tree, $keys, $prefix = '')
{
	if(is_array($tree))
	{
		foreach($tree as $key => $subTree)
		{
			if(in_array($key, $keys, true))
			{
				echo '- ' . $key . "\n";
			}
			elseif(!is_numeric($key))
			{
				$prefix .= '  ';
				echo $prefix . '|_ ' . $key . "\n";
			}
			printTree($subTree, $keys, $prefix);
		}
	}
	else
		echo $prefix . '|_ ' . $tree . "\n";
}
开发者ID:songjian,项目名称:songjian.github.io,代码行数:21,代码来源:tree.php

示例12: printTree

function printTree($tree, $root, $delim)
{
    reset($tree);
    #  print "<hr/>ROOT: $root<br/>";
    foreach ($tree as $node => $rec) {
        if (!in_array($node, $GLOBALS["nodesdone"])) {
            if (preg_match("#" . preg_quote($root) . "#i", $node)) {
                print '<li>';
                printf('<input type="checkbox" name="checkfolder[]" value="%s">&nbsp;', $node);
                print "<b>{$node}</b>\n";
                printf('<input type="checkbox" name="%s" id="%s" value="1"
          onchange="checkSubFolders(\'%s\');"> (add subfolders)', $node, $node, $node);
                print "</li>";
                print "<ul>\n";
                foreach ($tree[$node]["children"] as $leaf) {
                    if ($tree[$node . $delim . $leaf]) {
                        #          print "<ul>";
                        printTree($tree, $node . $delim . $leaf, $delim);
                        #          print "</ul>";
                    } else {
                        #  print "NO $node$delim$leaf <br/>";
                        print '<li>';
                        printf('<input type="checkbox" name="checkfolder[]" value="%s">&nbsp;', $node . $delim . $leaf);
                        #            print "$node.$delim";
                        print "{$leaf}</li>\n";
                    }
                    array_push($GLOBALS["nodesdone"], $node);
                }
                print "</ul>";
            } else {
                #     print "<li>$node</li>";
                #      print $root ."===". $node . "<br/>";
            }
        } else {
            #   print "<br/>Done: $node";
        }
    }
}
开发者ID:dehvCurtis,项目名称:phplist,代码行数:38,代码来源:import3.php

示例13: HandleExpand

function HandleExpand()
{
    global $db;
    if ($_REQUEST["treeId"] == "TreeCategories") {
        $res =& $db->query(CMD_SEL_ITEMS, array($_REQUEST["nodeId"]));
        if (PEAR::isError($res)) {
            printErr($res);
            exit;
        }
        $items = array();
        while ($row =& $res->fetchRow(DB_FETCHMODE_OBJECT)) {
            $customAttrs = array("categId" => $row->category_id);
            $items[] = array("nodeId" => $row->id, "name" => $row->art . " - " . $row->name, "state" => "item", "tp" => NODE_SITE_ITEM, "image" => getImageState($row), "customAttrs" => $customAttrs);
        }
        printTree($items, false);
    } else {
        if ($_REQUEST["treeId"] == "TreeOurSite") {
            $res =& $db->query(CMD_SEL_SUBCATEGORIES, array($_REQUEST["nodeId"]));
            if (PEAR::isError($res)) {
                printError($res);
                exit;
            }
            $categories = array();
            while ($row =& $res->fetchRow(DB_FETCHMODE_OBJECT)) {
                $catCount = getItemsCount($row->id);
                $state = null;
                if ($catCount > 0) {
                    $state = "collapsed";
                }
                $imgState = $row->viewmode == true ? "pics/ourcategoryHidden.png" : "pics/ourcategory.png";
                $categories[] = array("nodeId" => $row->id, "name" => $row->name, "state" => $state, "image" => $imgState);
            }
            addMovedItems($categories, $_REQUEST["nodeId"]);
            printTree($categories, false);
        }
    }
}
开发者ID:rivetweb,项目名称:old-auto-catalog,代码行数:37,代码来源:HandleExpand.php

示例14: simplexml_load_file

<?php

$cubename = $_GET['cube'];
include "../config.php";
include "views/views.php";
$xml = simplexml_load_file($xmlfile);
printTree($cubename, $img_cube, $img_plus);
开发者ID:apmuthu,项目名称:phpMyOLAP,代码行数:7,代码来源:tree.php

示例15: printTree

						<div class="col-md-4">							
							<select class="col-md-12 full-width-fix" name="link" id="link">								
								<option value="0">Unidentify</option>
								<?php 
printTree($link, '', '', $parsing->resource_id);
?>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 control-label">Parent:</label> 
						<div class="col-md-4">
							<select class="select2-01 col-md-12 full-width-fix" name="parent" id="parent">
							<option value="0">Unidentify</option>
							<?php 
printTree($menu_parent, '', '', $parsing->id);
?>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 control-label">Active:</label> 
						<div class="col-md-4">
							<select name="active" id="active" class="form-control">
								
								<option <?php 
if ($parsing->active == 0) {
    echo "selected";
} else {
    echo "";
}
开发者ID:ariborneo,项目名称:koperasi,代码行数:31,代码来源:menu-edit.php


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