CachingIterator::count
(PHP 5 >= 5.2.2, PHP 7, PHP 8)
CachingIterator::count — Return the number of elements in the cache
说明
Returns the number of elements in the cache. This is the number of elements iterated over so far, not the number of elements of the inner iterator. Elements are stored in the cache by key, so an element replaces any earlier element with the same key.
The CachingIterator::FULL_CACHE flag must be set.
参数
此函数没有参数。
返回值
Returns the number of elements in the cache.
错误/异常
Throws a BadMethodCallException if the
CachingIterator::FULL_CACHE flag is not set.
示例
示例 #1 CachingIterator::count() example
<?php
$iterator = new CachingIterator(
new ArrayIterator(['a', 'b', 'c']),
CachingIterator::FULL_CACHE
);
foreach ($iterator as $value) {
echo $value, ': ', count($iterator), "\n";
}
?>以上示例会输出:
a: 1 b: 2 c: 3
参见
- CachingIterator::getCache() - Retrieve the contents of the cache
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
