The ParentIterator class

(PHP 5 >= 5.1.0)

Introduction

This extended FilterIterator allows a recursive iteration using RecursiveIteratorIterator that only shows those elements which have children.

Class synopsis

ParentIterator extends RecursiveFilterIterator implements RecursiveIterator , OuterIterator {
/* Methods */
public bool accept ( void )
public __construct ( RecursiveIterator $iterator )
public ParentIterator getChildren ( void )
public bool hasChildren ( void )
public void next ( void )
public void rewind ( void )
}

Table of Contents

Коментарии

Автор:
ParentIterator is just a RecursiveFilterIterator whos accept() method calls the RecursiveFilterIterator->hasChildren() method to filter itself.

Basically, it filters out leaf nodes. For example

This would yield all files and directories
<?php
$rdi 
= new RecursiveDirectoryIterator(__DIR__);
$iter = new RecursiveIteratorIterator($rdiRecursiveIteratorIterator::CHILD_FIRST);
?>

wrapping that in a ParentIterator would filter it down to just directories
<?php
$rdi 
= new RecursiveDirectoryIterator(__DIR__);
$iter = new RecursiveIteratorIterator($rdiRecursiveIteratorIterator::CHILD_FIRST);
$dirsOnly = new ParentIterator($iter);
?>
2011-12-19 21:55:59
http://php5.kiev.ua/manual/ru/class.parentiterator.html
Easy example for understanding:
<?php

$iterator 
= new ParentIterator(
    new 
RecursiveArrayIterator(
        array(array(
123), 'A''B''C')
    )
);

foreach (
$iterator as $recursive) {
    foreach (
$recursive as $value) {
        echo 
$value PHP_EOL;
    }
}
?>

1
2
3
2019-05-12 14:24:29
http://php5.kiev.ua/manual/ru/class.parentiterator.html

    Поддержать сайт на родительском проекте КГБ