note 124945 added to class.norewinditerator
| From: | Anonymous@php.net | Date: | Sat, 25 Apr 2020 22:18:22 +0000 |
| Subject: | note 124945 added to class.norewinditerator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214535@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 109.57.54.31)
----
Manual Page -- http://php.net/manual/en/class.norewinditerator.php
Edit -- https://master.php.net/note/edit/124945
Del: integrated -- https://master.php.net/note/delete/124945/integrated
Del: useless -- https://master.php.net/note/delete/124945/useless
Del: bad code -- https://master.php.net/note/delete/124945/bad+code
Del: spam -- https://master.php.net/note/delete/124945/spam
Del: non-english -- https://master.php.net/note/delete/124945/non-english
Del: in docs -- https://master.php.net/note/delete/124945/in+docs
Del: other reasons-- https://master.php.net/note/delete/124945
Reject -- https://master.php.net/note/reject/124945
Search -- https://master.php.net/manage/user-notes.php