iterator_apply

Call a function for every element in an iterator

&reftitle.description; `int` `iterator_apply` `Traversable` `iterator` `callable` `callback` ``array``null```args`&null;

Calls a function for every element in an iterator.

&reftitle.parameters;

`iterator`

- The iterator object to iterate over.

`callback`

- 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.

  The function must return &true; in order to continue iterating over the `iterator`.

`args`

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

&reftitle.returnvalues;

Returns the iteration count.

&reftitle.examples;

### `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));
    ?>

&example.outputs;

    APPLES
    BANANAS
    CHERRIES

&reftitle.seealso;

- `array_walk`