©
本文档使用 PHP中文网手册 发布
(PHP 5 >= 5.1.0)
NoRewindIterator::__construct — Construct a NoRewindIterator
$iterator
)Constructs a NoRewindIterator.
iterator
The iterator being used.
A NoRewindIterator() based on the passed in
iterator
.
Example #1 NoRewindIterator::__construct() example
The second loop does not output because the iterator is only used once, as it does not rewind.
<?php
$fruit = array( 'apple' , 'banana' , 'cranberry' );
$arr = new ArrayObject ( $fruit );
$it = new NoRewindIterator ( $arr -> getIterator ());
echo "Fruit A:\n" ;
foreach( $it as $item ) {
echo $item . "\n" ;
}
echo "Fruit B:\n" ;
foreach( $it as $item ) {
echo $item . "\n" ;
}
?>
以上例程的输出类似于:
Fruit A: apple banana cranberry Fruit B: