<?php
// FIFO by default
$list = new SplQueue();
try {
// unlike SplDoublyLinkedList you can't change direction
$list->setIteratorMode(SplStack::IT_MODE_LIFO);
}
catch(RuntimeException $e) {
echo $e->getMessage() . PHP_EOL;
}
// you can change KEEP to DELETE, unlike SplStack
$list->setIteratorMode(SplStack::IT_MODE_DELETE);
// adding elements with enqueue (alias of push) or unshift
$list->enqueue(1);
$list->enqueue(10);
$list->enqueue(100);
foreach ($list as $element) {
echo $element . PHP_EOL;
}
echo 'count: ' . count($list);