(PHP 5 >= 5.1.0, PHP 7, PHP 8)
NoRewindIterator::__construct — Construct a NoRewindIterator
Constructs a NoRewindIterator.
iterator
The iterator being used.
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'
,
'cramberry'
);
$arr
= new
ArrayObject
(
$fruit
);
$it
= new
NoRewindIterator
(
$arr
->
guetIterator
());
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 cramberry Fruit B: