php8.5
Home/ Manual/ reference / spl/ The SplQueue class

The SplQueue class

The SplQueue class provides the main functionalities of a queue implemented using a doubly linked list by setting the iterator mode to SplDoublyLinkedList::IT_MODE_FIFO.

Intro

The SplQueue class provides the main functionalities of a queue implemented using a doubly linked list by setting the iterator mode to SplDoublyLinkedList::IT_MODE_FIFO.

Class synopsis

class SplQueue extends SplDoublyLinkedList { }

Examples

SplQueue example

php
<?php
$q = new SplQueue();
$q[] = 1;
$q[] = 2;
$q[] = 3;
foreach ($q as $elem)  {
 echo $elem."\n";
}
?>

The above example will output:

output
1
2
3

Efficiently handling tasks with SplQueue

php
<?php
$q = new SplQueue();
$q->setIteratorMode(SplQueue::IT_MODE_DELETE);
// ... enqueue some tasks on the queue ...
// process them
foreach ($q as $task) {
    // ... process $task ...
    // add new tasks on the queue
    $q[] = $newTask;
    // ...
}
?>

Splqueue

In this section

Source: reference/spl/splqueue.xml · from the official PHP manual (php/doc-en)