在线文档教程
PHP
SPL/Iterators

NoRewindIterator::__construct

NoRewindIterator::__construct

(PHP 5 >= 5.1.0, PHP 7)

NoRewindIterator::__construct — Construct a NoRewindIterator

Description

public NoRewindIterator::__construct ( Iterator $iterator )

Constructs a NoRewindIterator.

Parameters

iterator

The iterator being used.

Return Values

A NoRewindIterator() based on the passed in iterator.

Examples

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"; } ?>

The above example will output something similar to:

Fruit A: apple banana cranberry Fruit B:

See Also

  • NoRewindIterator::valid() - Validates the iterator

← NoRewindIterator

NoRewindIterator::current →

© 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

https://secure.php.net/manual/en/norewinditerator.construct.php