iterator_apply
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
iterator_apply — 為迭代器中每個元素呼叫一個使用者自定義函式
說明
循環迭代每個元素時呼叫某一回調函式。
參數
- 
iterator
- 
      需要循環迭代的類對象。 
- 
function
- 
      迭代到每個元素時的呼叫的回撥函式。 注意: 爲了遍歷 iterator這個函式必須返回true。
- 
args
- 
      傳遞到回撥函式的參數。 
返回值
返回已迭代的元素個數。
範例
示例 #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