CakeFest 2024: The Official CakePHP Conference

NoRewindIterator::__construct

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

NoRewindIterator::__constructConstruye un NoRewindIterator

Descripción

public NoRewindIterator::__construct(Iterator $iterator)

Construye un NoRewindIterator.

Parámetros

iterator

El iterador a ser usado.

Ejemplos

Ejemplo #1 Ejemplo de NoRewindIterator::__construct()

El segundo bucle no imprime nada porque el iterador solo puede usarse una vez, no se puede rebobinar.

<?php
$fruit
= array('manzana', 'banano', 'arándano');

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

El resultado del ejemplo sería algo similar a:

Fruit A:
manzana
banano
arándano
Fruit B:

Ver también

add a note

User Contributed Notes

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