3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fruits = new ArrayIterator(array( 'apple', 'banana', 'cherry', 'orange', 'pear' )); // Passing by the custom iterator only a substet of the elements foreach (new IteratorIterator(new LimitIterator($fruits ,2, 2)) as $fruit) { var_dump($fruit); }

preferences:
30.9 ms | 402 KiB | 5 Q