3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = new ArrayObject(range(1,11)); echo 'there are ' . $items->count() . ' total items' . "\r\n"; $itemIterator = $items->getIterator(); $cachingIterator = new CachingIterator($itemIterator); $limitIterator = new LimitIterator($cachingIterator, 0, 10); $i = 0; foreach ($limitIterator as $item) { ++$i; } echo 'first page has ' . $i . ' items' . "\r\n"; var_dump($cachingIterator->hasNext() === $itemIterator->valid());
based on AeUk7
Output for 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 7.3.26, 7.4.0 - 7.4.16, 8.0.0 - 8.0.3
there are 11 total items first page has 10 items bool(true)