本文整理汇总了PHP中Shopp::sort_tree方法的典型用法代码示例。如果您正苦于以下问题:PHP Shopp::sort_tree方法的具体用法?PHP Shopp::sort_tree怎么用?PHP Shopp::sort_tree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shopp
的用法示例。
在下文中一共展示了Shopp::sort_tree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort_tree
/**
* Recursively sorts a heirarchical tree of data
*
* @param array $item The item data to be sorted
* @param int $parent (internal) The parent item of the current iteration
* @param int $key (internal) The identified index of the parent item in the current iteration
* @param int $depth (internal) The number of the nested depth in the current iteration
* @return array The sorted tree of data
* @author Jonathan Davis
* @deprecated 1.3
**/
public static function sort_tree($items, $parent = 0, $key = -1, $depth = -1)
{
$depth++;
$position = 1;
$result = array();
if ($items) {
foreach ($items as $item) {
// Preserve initial priority
if (isset($item->priority)) {
$item->_priority = $item->priority;
}
if ($item->parent == $parent) {
$item->parentkey = $key;
$item->depth = $depth;
$item->priority = $position++;
$result[] = $item;
$children = Shopp::sort_tree($items, $item->id, count($result) - 1, $depth);
$result = array_merge($result, $children);
// Add children in as they are found
}
}
}
$depth--;
return $result;
}