An open API service indexing awesome lists of open source software.

https://github.com/czproject/relnode-php

Virtual tree helper class.
https://github.com/czproject/relnode-php

php tree

Last synced: over 1 year ago
JSON representation

Virtual tree helper class.

Awesome Lists containing this project

README

          

RelNode-PHP
-----------

Helper class.

``` php
addChild('sub/sub1/sub2/sub3', 'sub value');
$root->addChild('sub/sub1/sub2/sub3/sub4', 'sub value 2');
$root->addChild('sub/sub1/sub5', 'sub value 3');

/**
Structure:

$root
└── sub
└── sub1
├── sub2
│ └── sub3 (sub value) [first filled, one of the nearest]
│ └── sub4 (sub value 2)

└── sub5 (sub value 3) [one of the nearest]
*/

$node = $root->getFirstFilled();
echo $node->value; // 'sub value'

$nodes = $root->getNearestChildren();

foreach($nodes as $node) {
echo $node->value;

// Prints:
// 'sub value'
// 'sub value 3'
}

$node = $root->getNearestOneFor('sub/sub1/sub2/sub3/my-sub'); // returns NULL or RelNode instance
echo $node->value; // 'sub value'
$node = $root->getNearestOneFor('sub/sub1/sub2/sub3/sub4'); // returns NULL or RelNode instance
echo $node->value; // 'sub value 2'
```

------------------

License: [New BSD License](license.md)

Author: Jan Pecha, https://www.janpecha.cz/