PHP Doku:: Construct a NoRewindIterator - norewinditerator.construct.html

Verlauf / Chronik / History: (3) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige GrunderweiterungenStandard PHP Library (SPL)IteratorenThe NoRewindIterator classNoRewindIterator::__construct

Ein Service von Reinhard Neidl - Webprogrammierung.

The NoRewindIterator class

<<The NoRewindIterator class

NoRewindIterator::current>>

NoRewindIterator::__construct

(PHP 5 >= 5.1.0)

NoRewindIterator::__constructConstruct a NoRewindIterator

Beschreibung

NoRewindIterator::__construct ( Iterator $iterator )

Constructs a NoRewindIterator.

Parameter-Liste

iterator

The iterator being used.

Rückgabewerte

A NoRewindIterator() based on the passed in iterator.

Beispiele

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

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Fruit A:
apple
banana
cranberry
Fruit B:

Siehe auch


Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)