(PHP 5 >= 5.1.0, PHP 7, PHP 8)
iterator_apply — Call a function for every element in an iterator
Calls a function for every element in an iterator.
iteratorcallback
The callback function to call on every element.
This function only receives the given args, so it
is nullary by default. If count($args) === 3, for
instance, the callback function is ternary.
Hinweis: The function must return
truein order to continue iterating over theiterator.
argsargs is passed to the callback
callback as separate argument.
Returns the iteration count.
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