本文整理匯總了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;
}