PHP 5.5.15 is released

iterator_apply

(PHP 5 >= 5.1.0)

iterator_applyCall a function for every element in an iterator

Descrição

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

Calls a function for every element in an iterator.

Parâmetros

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.

Valor Retornado

Returns the iteration count.

Exemplos

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

O exemplo acima irá imprimir:

APPLES
BANANAS
CHERRIES

Veja Também

  • array_walk() - Aplica uma determinada funcão em cada elemento de um array

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top