array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.iterator-apply.php', 1 => 'iterator_apply', ), 'up' => array ( 0 => 'ref.spl.php', 1 => 'SPL 関数', ), 'prev' => array ( 0 => 'function.class-uses.php', 1 => 'class_uses', ), 'next' => array ( 0 => 'function.iterator-count.php', 1 => 'iterator_count', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/spl/functions/iterator-apply.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(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