©
本文檔使用 php中文網手册 發布
(PHP 5 >= 5.1.0)
This extended FilterIterator allows a recursive iteration using RecursiveIteratorIterator that only shows those elements which have children.
$iterator
)[#1] 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($rdi, RecursiveIteratorIterator::CHILD_FIRST);
?>
wrapping that in a ParentIterator would filter it down to just directories
<?php
$rdi = new RecursiveDirectoryIterator(__DIR__);
$iter = new RecursiveIteratorIterator($rdi, RecursiveIteratorIterator::CHILD_FIRST);
$dirsOnly = new ParentIterator($iter);
?>