本文整理匯總了PHP中Node::getLevel方法的典型用法代碼示例。如果您正苦於以下問題:PHP Node::getLevel方法的具體用法?PHP Node::getLevel怎麽用?PHP Node::getLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Node
的用法示例。
在下文中一共展示了Node::getLevel方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getLevel
/**
* Returns the level of this node in the tree
*
* @return int Tree level (1 = top level)
*/
public function getLevel()
{
if ($this->parent === null) {
return 0;
}
return $this->parent->getLevel() + 1;
}
示例2: __construct
/**
* Constructor.
*
* @param Node $parent (optional) parent node
*/
public function __construct($parent = null)
{
$this->parent = $parent;
if (null !== $parent) {
$this->level = 1 + $parent->getLevel();
}
}
示例3: getLevel
public function getLevel()
{
if ($this->parent) {
return $this->parent->getLevel() + 1;
} else {
return 0;
}
}
示例4: isChildOf
/**
* Returns a value indicating if this node is a child of the passed node.
* This just checks the levels of the nodes. If this node is at a greater
* level than the passed node if is a child of it.
*
* @param Node $node
* @return bool TRUE if the node is a child of the passed node, FALSE if not
*/
public function isChildOf($node)
{
return $this->getLevel() > $node->getLevel();
}