PHP.nl

iterator_apply

iterator_apply

Call a function for every element in an iterator

int **iterator_apply** Traversable $iterator callable $callback  $args

Calls a function for every element in an iterator.

iteratorThe iterator object to iterate over.

callback The callback function to call on every element. This function only receives the given , so it is nullary by default. If , for instance, the callback function is ternary.

  `args``count($args) === 3`> **Opmerking:** > The function must return true in order to
     continue iterating over the .
    `iterator`

args An of arguments; each element of is passed to the callback as separate argument. array``args``callback

Returns the iteration count.

Voorbeeld: 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));
?>
APPLES
BANANAS
CHERRIES

array_walk