迭代器
在线手册:中文  英文

The ParentIterator class

(PHP 5 >= 5.1.0)

简介

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

类摘要

ParentIterator extends RecursiveFilterIterator implements RecursiveIterator , OuterIterator {
/* 方法 */
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


迭代器
在线手册:中文  英文

用户评论:

Anonymous (2011-12-19 19:55:59)

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);
?>

易百教程