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


PHP buildTree函数代码示例

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


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

示例1: buildTree

function buildTree($graph, $nodeId, $array, $namespace)
{
    if (!isset($nodeId)) {
        $nodeId = $graph->newBNode();
    }
    $me = $graph->resource($nodeId);
    foreach ($array as $key => $value) {
        $type = gettype($value);
        if ($type != "array") {
            if (substr($value, 0, 7) === "http://") {
                $me->addResource($namespace . ":" . $key, $value);
            } elseif (substr($value, 0, 8) === "https://") {
                $me->addResource($namespace . ":" . $key, $value);
            } elseif (is_numeric($value)) {
                $me->add($namespace . ":" . $key, intval($value));
            } elseif ($value != "") {
                $me->add($namespace . ":" . $key, $value);
            }
        } else {
            $bn = $graph->newBNode();
            $me->add($namespace . ":" . $key, $bn);
            buildTree($graph, $bn, $value, $namespace);
        }
    }
}
开发者ID:RaphaelManke,项目名称:chefkochWrapperToRDF,代码行数:25,代码来源:utils.php

示例2: buildTree

function buildTree($dir)
{
    $list = '';
    foreach (new RecursiveDirectoryIterator($dir) as $filename => $file) {
        $list .= '<li>' . (!$file->isDir() ? '<a href="javascript:loadFile(\'' . $filename . '\');">' : '') . str_replace('.let', '', $file->getFilename()) . ($file->isDir() ? buildTree($file) : '</a>') . '</li>';
    }
    return "<ul>{$list}</ul>";
}
开发者ID:shaunxcode,项目名称:phlisp,代码行数:8,代码来源:filelist.php

示例3: buildTree

function buildTree($tree, $q)
{
    $test = snag_sql_query($tree, $q);
    if (!empty($test)) {
        foreach ($test as $nid => $testy) {
            $test[$nid]["children"] = buildTree($tree, $testy["id"]);
        }
    }
    return $test;
}
开发者ID:ixias,项目名称:web-thing,代码行数:10,代码来源:lib.php

示例4: smGetCat

 function smGetCat()
 {
     global $cats;
     if (!empty($cats)) {
         $tree = buildTree($cats);
         $result = smGetCatItm($tree);
     }
     //        debug($result);
     return $result;
 }
开发者ID:gblok,项目名称:rsc,代码行数:10,代码来源:sitemap.php

示例5: buildTree

function buildTree(array $source, $search)
{
    $out = array();
    foreach ($source[$search] as $key => $node) {
        if (isset($source[$node])) {
            $out[$key] = buildTree($source, $node);
            unset($source[$node]);
        } else {
            $out[$key] = $node;
        }
    }
    return $out;
}
开发者ID:cactucs,项目名称:stormdb,代码行数:13,代码来源:StormDBUtils.php

示例6: preparedMenuLinks

 protected function preparedMenuLinks($menus)
 {
     if (!empty($menus)) {
         $menuItems = array();
         //fetch all parents & childrens
         foreach ($menus as $menu) {
             $menuData = array('label' => $menu->label, 'link' => $this->makeContentLink($menu), 'parent_id' => $menu->parent_id);
             $id = $menu->id;
             $menuItems[$id] = $menuData;
         }
         return buildTree($menuItems);
     }
     return array();
 }
开发者ID:rodrane,项目名称:ravel,代码行数:14,代码来源:FrontMenuBuild.php

示例7: buildTree

function buildTree(array $data, $parent = 0)
{
    $tree = array();
    foreach ($data as $d) {
        if ($d->parent_id == $parent) {
            $children = buildTree($data, $d->id);
            if (!empty($children)) {
                $d->_children = $children;
            }
            $tree[] = $d;
        }
    }
    return $tree;
}
开发者ID:ariborneo,项目名称:koperasi,代码行数:14,代码来源:tree_helper.php

示例8: buildTree

function buildTree(array $data, $parent = 6)
{
    $tree = array();
    foreach ($data as $d) {
        if ($d['id'] == $parent) {
            $children = buildTree($data, $d['parent']);
            // set a trivial key
            if (!empty($children)) {
                $d['_children'] = $children;
            }
            $tree[] = $d;
        }
    }
    return $tree;
}
开发者ID:atonevbg,项目名称:snippets,代码行数:15,代码来源:snippets2.php

示例9: buildTree

function buildTree(array &$elements, $parentId = 0, $shift = 0)
{
    $branch = array();
    foreach ($elements as &$element) {
        if ($element['parent_id'] == $parentId) {
            $children = buildTree($elements, $element['id'], $shift + 3);
            if ($children) {
                $element['children'] = $children;
            }
            $element['shift'] = $shift;
            $branch[$element['id']] = $element;
            unset($element);
        }
    }
    return $branch;
}
开发者ID:alex-petkevich,项目名称:proweb5,代码行数:16,代码来源:arrays.php

示例10: buildTree

 function buildTree(array $elements, $parentId = 0)
 {
     $branch = array();
     foreach ($elements as $element) {
         if ($element['mdl_parent'] == $parentId) {
             $children = buildTree($elements, $element['id']);
             if ($children) {
                 $element['children'] = $children;
             } else {
                 $element['children'] = 0;
             }
             $branch[] = $element;
         }
     }
     return $branch;
 }
开发者ID:ronaldesc007,项目名称:alu,代码行数:16,代码来源:ViewsDataMiddleware.php

示例11: buildTree

function buildTree(array &$elements, $parentId = 0)
{
    $branch = array();
    foreach ($elements as $element) {
        if ($element['parent_id'] == $parentId) {
            $children = buildTree($elements, $element['id']);
            if ($children) {
                $element['children'] = $children;
            }
            $branch[] = $element;
            // $branch[$element['id']] = $element;
            unset($elements[$element['id']]);
        }
    }
    return $branch;
}
开发者ID:WisnuDiStefano,项目名称:int,代码行数:16,代码来源:testpost.php

示例12: getBranch

function getBranch($tree, $parentId = 1)
{
    $branch = array();
    foreach ($tree as $element) {
        if ($element['parent'] == $parentId) {
            $children = buildTree($tree, $element['categoryID']);
            if (!empty($children)) {
                foreach ($children as $k => $v) {
                    $branch[] = $v['categoryID'];
                }
            }
            $branch[] = $element['categoryID'];
        }
    }
    return $branch;
}
开发者ID:gblok,项目名称:rsc,代码行数:16,代码来源:diz_function.php

示例13: load

 private function load()
 {
     $last = array(-1 => -1);
     $beforeType = 0;
     $data = array();
     $keys = array();
     $file = fopen($this->fileName, 'r');
     $key = 0;
     while (!feof($file)) {
         $value = fgets($file);
         $type = substr($value, 0, 1) * 1;
         $data = substr($value, 1, strlen($value) - 2);
         $this->types[] = $type;
         $this->data[] = $data;
         $this->parents[$key] = $last[$type - 1];
         $this->linesBytes[] = fTell($file);
         if ($type - 1 > $beforeType) {
             $line = $key + 1;
             $excMsg = "Incorrect declaration of type in '" . $this->database . "' line " . $line;
             throw new StormDBException($excMsg, 0);
         }
         if ($type == 0) {
             $this->collections[] = $data;
         }
         $last[$type] = $key;
         $beforeType = $type;
         $key++;
     }
     $parentsBuild = array('BASE' => array());
     for ($depth = 0; $depth < 10; $depth++) {
         foreach ($this->types as $key => $type) {
             if ($type == $depth) {
                 if ($this->parents[$key] >= 0) {
                     if (!isset($parentsBuild[$this->parents[$key]])) {
                         $parentsBuild[$this->parents[$key]] = array();
                     }
                     $parentsBuild[$this->parents[$key]][$key] = $key;
                 } else {
                     $parentsBuild['BASE'][$key] = $key;
                 }
             }
         }
     }
     $this->build = assignNames(buildTree($parentsBuild, 'BASE'), $this->data);
 }
开发者ID:cactucs,项目名称:stormdb,代码行数:45,代码来源:StormDB.php

示例14: buildTree

/** 
 * Construct a tree based on table entries
 * @param	array	current node, (current parent)
 * @param	mixed	a set of parents, where each parents is in the format of [parent]=>children
 *					should remain the same throughout the recursion.
 * @return	A tree structure representation of the content entries.
 * @author	Harris Wong
 */
function buildTree($current, $content_array)
{
    $folder = array();
    foreach ($current as $order => $content_id) {
        //if has children
        if (isset($content_array[$content_id])) {
            $wrapper[$content_id] = buildTree($content_array[$content_id], $content_array);
        }
        //no children.
        if ($wrapper) {
            $folder['order_' . $order] = $wrapper;
            unset($wrapper);
        } else {
            $folder['order_' . $order] = $content_id;
        }
    }
    return $folder;
}
开发者ID:vicentborja,项目名称:ATutor,代码行数:26,代码来源:ustep_content_conversion.php

示例15: buildTree

function buildTree($data, $parent = 0)
{
    $tree = array();
    foreach ($data as $d) {
        if ($d['parent'] == $parent) {
            $children = buildTree($data, $d['id']);
            // set a trivial key
            if (!empty($children)) {
                $d['categories'] = $children;
                $d = push_posts($d);
            } else {
                $d = push_posts($d);
            }
            $tree[] = $d;
        }
    }
    return $tree;
}
开发者ID:amreenshaik9,项目名称:sample-projects,代码行数:18,代码来源:GetHirerchyCategories.php


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