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.
- Host: GitHub
- URL: https://github.com/czproject/relnode-php
- Owner: czproject
- License: other
- Created: 2013-04-28T15:51:35.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2017-12-27T14:15:47.000Z (over 8 years ago)
- Last Synced: 2025-02-12T06:53:55.898Z (over 1 year ago)
- Topics: php, tree
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
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/