(PHP 5 >= 5.1.0, PHP 7)
Call a function for every element in an iterator
int iterator_apply ( Traversable $iterator, callable $function [, array $args ] )
Calls a function for every element in an iterator.
Parameters:
iterator
The class to iterate over.
function
The callback function to call on every element.
Note: The function must return
TRUE
in order to continue iterating over theiterator
.
args
Arguments to pass to the callback function.
Returns:
Returns the iteration count.
Examples:
iterator_apply() example
1 2 3 4 5 6 7 8 9 | <?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 )); ?> |
The above example will output:
APPLES BANANAS CHERRIES
See also:
Please login to continue.