計算迭代器中元素的個數

iterator_count

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

iterator_count計算迭代器中元素的個數

說明

iterator_count(Traversable $iterator): int

計算迭代器中的元素個數。

參數

iterator

要計數的迭代器。

返回值

迭代器iterator中的元素個數。

範例

示例 #1 iterator_count() example

<?php
$iterator 
= new ArrayIterator(array('recipe'=>'pancakes''egg''milk''flour'));
var_dump(iterator_count($iterator));
?>

以上例程會輸出:

int(4)

Leave a Reply

Your email address will not be published. Required fields are marked *