本文整理汇总了PHP中Node::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::insert方法的具体用法?PHP Node::insert怎么用?PHP Node::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertByPath
/**
* Recursively inserts a path of nodes
*
* @param Node $curr_node
* @param string $path a slash delimited path of node names
* @param array $array optional data array added to last node in the path
*/
public function insertByPath(&$curr_node, $path = '', $array = null)
{
if (is_string($path)) {
$p = explode('/', $path);
$n = array_shift($p);
if ($curr_node instanceof Node) {
$curr_name = $curr_node->getName();
}
if ($curr_name === $n) {
if (isset($p[0])) {
$n = $p[0];
}
if ($next_node = $curr_node->getNode($n)) {
$next_node = $next_node;
} else {
$next_node = $curr_node;
}
} else {
$new_node = self::build($n);
$new_node->setData($array);
$curr_node->insert($new_node);
$next_node = $new_node;
}
if ($n !== '') {
$remaining_path = implode('/', $p);
while (count($p) > 0) {
return $this->insertByPath($next_node, $remaining_path, $array);
}
}
}
}
示例2: array
public $children;
public $parent;
function __construct($name)
{
$this->name = $name;
$this->children = array();
$this->parent = null;
}
function insert($node)
{
$node->parent = $this;
$this->children[] = $node;
}
function __destruct()
{
var_dump($this->name);
unset($this->name);
unset($this->children);
unset($this->parent);
}
}
$a = new Node('A');
$b = new Node('B');
$c = new Node('C');
$a->insert($b);
$a->insert($c);
unset($a);
unset($b);
unset($c);
var_dump(gc_collect_cycles());
echo "ok\n";
示例3: insert
public function insert(PSNode $node)
{
/* Sobrescrita para Tipagem Correta */
parent::insert($node);
/* Verificação de Alturas */
$left = $this->getLeft();
$right = $this->getRight();
/* Configuração de Alturas */
$lheight = 0;
$rheight = 0;
/* Altura da Subárvore Esquerda */
if ($left !== NULL) {
$lheight = $left->getHeight();
}
/* Altura da Subárvore Direita */
if ($right !== NULL) {
$rheight = $right->getHeight();
}
/* Altura Local */
$height = $lheight < $rheight ? $rheight : $lheight;
$this->setHeight($height + 1);
return $this;
}
示例4: var_dump
$node->insert('foo');
echo var_dump($node);
$node->insert('bar');
echo var_dump($node);
echo var_dump($node->getMember(2));
$node->delete(1);
echo var_dump($node);
$node->insert(new Node());
echo var_dump($node);
//NOTE: properties created dynamically are public by default
#$node->{3} = null;
#echo var_dump($node);
foreach ($node as $i => $property) {
echo var_dump($property);
}
$node3 = new Node();
$node3->insert('dog');
$node->{3}->insert($node3);
#$node->setMember(3, 'baz'); // replaces the previously inserted node
$node->insert(new Node());
$node->setMember(2, 'baz');
$next_node = new Node();
$next_node->insert('bin');
echo var_dump($next_node);
$node->insert($next_node);
echo var_dump($node);
?>
</pre>
<?php
$html = $node->emitHTML();
echo $html;