(PHP 5 >= 5.1.0, PHP 7, PHP 8)
iterator_apply — ユーザー関数をイテレータのすべての要素でコールする
イテレータ内のすべての要素に対して関数をコールします。
イテレータの要素数を返します。
例1 iterator_apply() の例
<?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