SPL Funzioni
PHP Manual

iterator_apply

(PHP 5 >= 5.1.0)

iterator_applyCall a function for every element in an iterator

Descrizione

int iterator_apply ( Traversable $iterator , callable $function [, array $args ] )

Calls a function for every element in an iterator.

Elenco dei parametri

iterator

The class to iterate over.

function

The callback function to call on every element.

Nota: The function must return TRUE in order to continue iterating over the iterator.

args

Arguments to pass to the callback function.

Valori restituiti

Returns the iteration count.

Esempi

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

Il precedente esempio visualizzerĂ :

APPLES
BANANAS
CHERRIES

Vedere anche:


SPL Funzioni
PHP Manual