(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.
This function has no parameters.
Returns the number of elements in the cache.
Throws a BadMethodCallException if the
CachingIterator::FULL_CACHE flag is not set.
Example #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";
}
?>The above example will output:
a: 1 b: 2 c: 3