The NoRewindIterator class
(PHP 5 >= 5.1.0)
Introduction
This iterator cannot be rewound.
Class synopsis
Table of Contents
- NoRewindIterator::__construct — Construct a NoRewindIterator
- NoRewindIterator::current — Get the current value
- NoRewindIterator::getInnerIterator — Get the inner iterator
- NoRewindIterator::key — Get the current key
- NoRewindIterator::next — Forward to the next element
- NoRewindIterator::rewind — Prevents the rewind operation on the inner iterator.
- NoRewindIterator::valid — Validates the iterator
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие базовые расширения
- Стандартная библиотека PHP (SPL)
- Класс AppendIterator
- Класс ArrayIterator
- Класс CachingIterator
- Класс CallbackFilterIterator
- Класс DirectoryIterator
- Класс EmptyIterator
- Класс FilesystemIterator
- Класс FilterIterator
- Класс GlobIterator
- Класс InfiniteIterator
- Класс IteratorIterator
- Класс LimitIterator
- Класс MultipleIterator
- Класс NoRewindIterator
- Класс ParentIterator
- Класс RecursiveArrayIterator
- Класс RecursiveCachingIterator
- Класс RecursiveCallbackFilterIterator
- Класс RecursiveDirectoryIterator
- Класс RecursiveFilterIterator
- Класс RecursiveIteratorIterator
- Класс RecursiveRegexIterator
- Класс RecursiveTreeIterator
- Класс RegexIterator
Коментарии
As its name implies, NoRewindIterator doesn't invoke the "rewind" method when It reaches the end of the iterator.
Let's demonstrate it by two examles.
In this example the "rewind" method will be invoked after when the "foreache" reaches its end, so, we can repeat printing the same values as many times as we want:
<?PHP
$iterator = new ArrayIterator(['PHP', 'Python', 'Go']);
foreach ($iterator as $item) {
echo $item.PHP_EOL;
}
foreach ($iterator as $item) {
echo $item.PHP_EOL;
}
?>
By using the NoRewindIterator, the "rewind" won't be invoked, so, we can't do as we did in previous example:
<?PHP
$iterator = new ArrayIterator(['PHP', 'Python', 'Go']);
$iterator = new NoRewindIterator($iterator);
foreach ($iterator as $item) {
echo $item.PHP_EOL;
}
// doesn't do anything
foreach ($iterator as $item) {
echo $item.PHP_EOL;
}
?>