PHP 8.4.0 RC4 available for testing

NoRewindIterator::__construct

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

NoRewindIterator::__constructConstruct a NoRewindIterator

Опис

public NoRewindIterator::__construct(Iterator $iterator)

Constructs a NoRewindIterator.

Параметри

iterator

The iterator being used.

Приклади

Приклад #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:

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top