CachingIterator::hasNext
(PHP 5, PHP 7, PHP 8)
CachingIterator::hasNext — Check whether the inner iterator has a valid next element
Description
Checks whether there is an element after the current one.
As the CachingIterator is one element ahead of its inner iterator, this checks whether the inner iterator is valid, which makes it possible to tell whether the current element is the last one before moving past it.
Parameters
This function has no parameters.
Examples
Example #1 Detecting the last element
<?php
$fruits = new CachingIterator(new ArrayIterator(['apple', 'banana', 'cherry']));
foreach ($fruits as $fruit) {
echo $fruit;
if ($fruits->hasNext()) {
echo ', ';
}
}
?>The above example will output:
apple, banana, cherry
See Also
- CachingIterator::valid() - Check whether the current element is valid
- CachingIterator::next() - Move the iterator forward
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
