The Wayback Machine - https://web.archive.org/web/20250113234820/https://www.geeksforgeeks.org/php-dsqueue-functions-complete-reference/
Open In App

PHP Ds\Queue Functions Complete Reference

Last Updated : 25 Jan, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

Syntax:

public Ds\Queue::functionname()

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

PHP




<?php
 
// Declare new Queue
$q = new \Ds\Queue();
 
// Add elements to the Queue
$q->push("One");
$q->push("Two");
$q->push("Three");
 
echo "Initial Queue: \n";
// Display the Queue
print_r($q);
 
// clear the Queue
$q->clear();
 
echo "\nQueue after clearing:\n";
print_r($q);
 
?>


Output:

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

Description

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.

Become a Full-Stack Developer and also get 90% fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.

After successfully processing refunds worth over INR 5 Cr, GeeksforGeeks is back with the Three 90 challenge and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!


Next Article

Similar Reads

three90RightbarBannerImg