Skip to content

czproject/relnode-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RelNode-PHP

Helper class.

<?php
$root = new Cz\RelNode;
$root->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
Author: Jan Pecha, https://www.janpecha.cz/

About

Virtual tree helper class.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages