iterator_count
Calculate the number of elements in the iterator
Function name: iterator_count()
Applicable version: PHP 5, PHP 7
Function description: the iterator_count() function is used to calculate the number of elements in the iterator.
usage:
iterator_count ( Traversable $iterator ) : int
parameter:
$iterator
: The iterator object to count (implements the Traversable interface).Return value:
Example:
// 创建一个数组迭代器$array = ['apple', 'banana', 'cherry']; $iterator = new ArrayIterator($array); // 计算迭代器中的元素数量$count = iterator_count($iterator); echo "数组中的元素数量为:$count"; // 输出:数组中的元素数量为:3
Notes: