3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $doubly=new SplDoublyLinkedList(); $doubly->push(array('name'=>'Naruto')); $doubly->push(array('name'=>'Sakura')); $doubly->push(array('name'=>'Neji')); $doubly->push(array('name'=>'Sasuke')); var_dump($doubly); echo '<br/> FIFO Traversing<br/>'; $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); $doubly->rewind(); foreach($doubly as $key=>$value) { echo '<br/>Traversed:'.$key.' '.$value['name']; } echo '<br/>LIFO Traversing - Keep mode <br/>'; $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); $doubly->rewind(); foreach($doubly as $key=>$value) { echo '<br/>Traversed:'.$key.' '.$value['name']; } echo '<br/>LIFO Traversing - Delete mode <br/>'; $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_DELETE); $doubly->rewind(); foreach($doubly as $key=>$value) { if($key == 2) break; echo '<br/>Traversed:'.$key.' '.$value['name']; } var_dump($doubly);
based on a3iFn
Output for 5.3.0 - 7.1.0
object(SplDoublyLinkedList)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(0) ["dllist":"SplDoublyLinkedList":private]=> array(4) { [0]=> array(1) { ["name"]=> string(6) "Naruto" } [1]=> array(1) { ["name"]=> string(6) "Sakura" } [2]=> array(1) { ["name"]=> string(4) "Neji" } [3]=> array(1) { ["name"]=> string(6) "Sasuke" } } } <br/> FIFO Traversing<br/><br/>Traversed:0 Naruto<br/>Traversed:1 Sakura<br/>Traversed:2 Neji<br/>Traversed:3 Sasuke<br/>LIFO Traversing - Keep mode <br/><br/>Traversed:3 Sasuke<br/>Traversed:2 Neji<br/>Traversed:1 Sakura<br/>Traversed:0 Naruto<br/>LIFO Traversing - Delete mode <br/><br/>Traversed:3 Sasukeobject(SplDoublyLinkedList)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(3) ["dllist":"SplDoublyLinkedList":private]=> array(3) { [0]=> array(1) { ["name"]=> string(6) "Naruto" } [1]=> array(1) { ["name"]=> string(6) "Sakura" } [2]=> array(1) { ["name"]=> string(4) "Neji" } } }
Output for 5.0.0 - 5.2.17
Fatal error: Class 'SplDoublyLinkedList' not found in /in/DpNeV on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '|', expecting '(' in /in/DpNeV on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '|', expecting '(' in /in/DpNeV on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'('' in /in/DpNeV on line 10
Process exited with code 255.