Open In App
Related Articles

PHP Ds\Queue Functions Complete Reference

Improve Article
Save Article
Like Article

A Queue is a linear data structure that follows a particular order in which the operations are performed. The order of queue is First In First Out (FIFO).

Requirements: PHP 7 is required for both extension and the compatibility polyfill. 

Installation: The easiest way to install data structure by using the PECL extension.

pecl install ds


public Ds\Queue::functionname()

Example: Below programs illustrate the Ds\Queue::clear() function in PHP:


// Declare new Queue
$q = new \Ds\Queue();
// Add elements to the Queue
echo "Initial Queue: \n";
// Display the Queue
// clear the Queue
echo "\nQueue after clearing:\n";


Initial Queue: 
Ds\Queue Object
    [0] => One
    [1] => Two
    [2] => Three

Queue after clearing:
Ds\Queue Object

Complete list of data structure DS\Queue:

PHP Ds\Queue Functions


allocate()Allocate memory for a Queue class instance.
capacity()Check the current capacity of a Queue instance.
clear()Clear all of the elements from a Queue instance.
copy()Create a shallow copy of a particular Queue instance.
count()Get the count of elements present in a Queue instance.
isEmpty()Whether a particular Queue instance is empty or not.
peek()Get the value present at the front of a Queue.
pop()Remove and return the value present at the top of the Queue.
push()Push or insert values in a PriorityQueue instance.
toArray()Convert a Queue into an associative array in PHP.
Last Updated : 25 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials