3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $test_array = array('Element 1', 'Element 2', 'Element 3', 'Element 4', 'Element 5', 'Element 6'); $infArray = array(1, 2, 3); $arrayIterator = new ArrayIterator($infArray); var_dump($arrayIterator->current()); $infiniteIterator = new InfiniteIterator(new ArrayIterator($infArray)); var_dump($infiniteIterator->current()); $limit = 10; foreach($test_array as $test){ echo $test . ' ' . $infiniteIterator->current() . '<br/>' . PHP_EOL; $infiniteIterator->next(); if (!($limit-->0)) { break; } }
Output for 5.1.0 - 7.1.0
int(1) NULL Element 1 <br/> Element 2 2<br/> Element 3 3<br/> Element 4 1<br/> Element 5 2<br/> Element 6 3<br/>
Output for 5.0.0 - 5.0.5
int(1) Fatal error: Class 'InfiniteIterator' not found in /in/uQLdu on line 7
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: arrayiterator in /in/uQLdu on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: arrayiterator in /in/uQLdu on line 4