iterator_apply
(PHP 5 >= 5.1.0)
iterator_apply — Call a function for every element in an iterator
Beschreibung
Calls a function for every element in an iterator.
Parameter-Liste
-
iterator -
The class to iterate over.
-
function -
The callback function to call on every element.
Hinweis: The function must return
TRUEin order to continue iterating over theiterator. -
args -
Arguments to pass to the callback function.
Rückgabewerte
Returns the iteration count.
Beispiele
Beispiel #1 iterator_apply() example
<?php
function print_caps(Iterator $iterator) {
echo strtoupper($iterator->current()) . "\n";
return TRUE;
}
$it = new ArrayIterator(array("Apples", "Bananas", "Cherries"));
iterator_apply($it, "print_caps", array($it));
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
APPLES BANANAS CHERRIES
Siehe auch
- array_walk() - Wendet eine vom Benutzer gelieferte Funktion auf jedes Element eines Arrays an