public function traverseNodesAndFindBy($propName, $propValue, Collection $nodes = null)
    {
        // Nodes are null so nothing to Traverse.
        if (is_null($nodes)) {
            return null;
        }

        foreach ($nodes as $node) {
            if ($node->{$propName} == $propValue) {
                return $node;
            }

            if ($node->hasChildren()) {
                $node = $this->traverseNodesAndFindBy($propName, $propValue, $node->getChildren());

                if (! is_null($node) && $node instanceof self) {
                    return $node;
                }
            }
        }

        // Nothing Found.
        return null;
    }
public function traverseNodesAndFindBy($propName, $propValue, Collection $nodes = null)
    {
        // Nodes are null so nothing to Traverse.
        if (is_null($nodes)) {
            return null;
        }

        foreach ($nodes as $node) {
            if ($node->{$propName} == $propValue) {
                return $node;
            }

            if ($node->hasChildren()) {
                $node = $this->traverseNodesAndFindBy($propName, $propValue, $node->getChildren());

                if (! is_null($node) && $node instanceof self) {
                    return $node;
                }
            }
        }

        // Nothing Found.
        return null;
    }
public function traverseNodesAndFindBy ( $ propName , $ propValue , Collection $ nodes = null ) { // Nodes are null so nothing to Traverse. if ( is_null ( $ nodes ) ) { return null ; } foreach ( $ nodes as $ node ) { if ( $ node -> { $ propName } == $ propValue ) { return $ node ; } if ( $ node -> hasChildren ( ) ) { $ node = $ this -> traverseNodesAndFindBy ( $ propName , $ propValue , $ node -> getChildren ( ) ) ; if ( ! is_null ( $ node ) && $ node instanceof self ) { return $ node ; } } } // Nothing Found. return null ; }
Traverse Collection of Nodes and return specific Node if
criteria matches.

@param string     $propName
@param string     $propValue
@param Collection $nodes

@return TraitTreeNode|ConsumptionPreferencesCategoryNode|ConsumptionPreferencesNode|null
Traverse Collection of Nodes and return specific Node if criteria matches .