Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

PHP Ds\PriorityQueue Functions Complete Reference

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

PriorityQueue is similar to a Queue data structure. The elements of the priority queue are pushed into the queue with a given priority. The highest priority element will always been present at the front of the queue. The priority queue is implemented using the max heap.

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\PriorityQueue::functionName()

Example: Below programs illustrate the Ds\PriorityQueue::count() Function in PHP:


// Declare new PriorityQueue
$pq = new \Ds\PriorityQueue();
// Add elements to the PriorityQueue
$pq->push("One", 1);
$pq->push("Two", 2);
$pq->push("Three", 3);
// Count the number of elements
// in this PriorityQueue



Complete list of PHP Ds\PriorityQueue Functions:

PHP Ds\PriorityQueue Functions


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