php教程

iterator_count

(PHP 5 >= 5.1.0, PHP 7)

iterator_count计算迭代器中元素的个数

说明

iterator_count ( Traversable $iterator ) : int

计算迭代器中的元素个数。

参数

iterator

要计数的迭代器。

返回值

迭代器iterator中的元素个数。

范例

Example #1 iterator_count() example

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

以上例程会输出:

int(4)

User Contributed Notes

Youri van den Bogert 06-Feb-2018 08:31
Note: using count on a array object will include non filtered objects. Using iterator_count will not include filtered objects.

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788