本文整理汇总了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);
}
}
}
示例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>";
}
示例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;
}
示例4: smGetCat
function smGetCat()
{
global $cats;
if (!empty($cats)) {
$tree = buildTree($cats);
$result = smGetCatItm($tree);
}
// debug($result);
return $result;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}