update : 2015.11.03
php.shukuma.com

검색:
 
 
Call a function for every element in an iterator

iterator_apply

(PHP 5 >= 5.1.0)

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

인수

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

args

Arguments to pass to the callback function.

반환값

Returns the iteration count.

예제

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

위 예제의 출력:

APPLES
BANANAS
CHERRIES

참고

  • array_walk() - 배열의 각 원소에 대해서 특정 함수를 적용