3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ll = new SplDoublyLinkedList(); $ll->push('one'); $ll->push('two'); $ll->push('three'); $ll->push('four'); $ll->rewind(); $iterations_done = iterator_apply($ll, function(Iterator $it) { echo $it->key(),"\t->", $it->current(),"\t->", ucfirst($it->current()),".\n"; $it->next(); return true; }, array($ll)); echo "Did iterate {$iterations_done} times \n";
Output for 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 7.3.28, 7.4.0 - 7.4.16, 8.0.0 - 8.0.3
0 ->one ->One. 1 ->two ->Two. 2 ->three ->Three. 3 ->four ->Four. Did iterate 4 times