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

PHP Ds\PriorityQueue Functions Complete Reference

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

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

Syntax:

public Ds\PriorityQueue::functionName()

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

PHP




<?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
print_r($pq->count());
 
?>


Output: 

3

Complete list of PHP Ds\PriorityQueue Functions:

PHP Ds\PriorityQueue Functions

Description

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.

Previous Article
Next Article

Similar Reads

PHP Calendar Functions Complete Reference
The calendar extension contains a series of functions to represent the calendar date into a different format. The standard date is based on Julian Day Count. The date count starting from January 1st, 4713 B.C. is known as Julian Day Count. First, the date is converted into Julian Day Count and then converted into a calendar system. Example: The pro
2 min read
PHP Gmagick Functions Complete Reference
Gmagick is the PHP extension used to create, modify and obtain meta information of an image using GraphicsMagick API. The Gmagick consists of Gmagick, GmagickDraw, and GmagickPixel class. Example: Below programs illustrate the Gmagick::getpackagename()Function in PHP: Original Image: C/C++ Code <?php // Create new Gmagick object $im = new Gmagic
3 min read
PHP Ds\Deque Functions Complete Reference
A deque data structure is used to store the sequence of values in a contiguous memory buffer which grows and shrinks automatically. The deque is the abbreviation of "double-ended queue". Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structure by using the PECL extens
3 min read
PHP Ds\Set Functions Complete Reference
Set is the collection of unique values. The implementation of Ds\Set is similar to the Ds\Map which creates a hash table. The values of Ds\Set are used as key and the mapped values are ignored. Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structure by using the PECL
2 min read
PHP Ds\Map Functions Complete Reference
A Map is a sequential collection of key-value pair which is very similar to the array. The key of a map can be of any type and it is unique. If any value added to the same key in a Map then the map value will replace. It is the efficient Data Structure in PHP 7 to provide the alternative of an array. Requirements: PHP 7 is required for both extensi
3 min read
PHP Filesystem Functions Complete Reference
The Filesystem function is used to access and manipulate filesystem. It is the part of PHP code so no need to install these functions. For accessing the files on the system, the file path will be used. On Unix system, forward slash (/) is used as a directory separator and on Windows platform, both forward slash (/) and backward slash (\) will be us
4 min read
PHP Image Processing and GD Functions Complete Reference
Image processing and GD functions are used to create and manipulate image files in different image formats including GIF, PNG, JPEG, WBMP, and XPM. PHP can deliver the output image directly to the browser. The image processing and GD functions are used to compile the image functions for this work. It can also require other libraries, depending on t
3 min read
PHP GMP Functions Complete Reference
The GMP function uses arbitrary-length integers to perform mathematical operations. The GMP function contains the GMP number as an argument. Example: Program to perform the division of GMP numbers when numeric strings as GMP numbers are passed as arguments. C/C++ Code <?php // PHP program to perform division of // GMP numbers passed as arguments
3 min read
PHP String Functions Complete Reference
Strings are a collection of characters. For example, 'G' is the character and 'GeeksforGeeks' is the string. Installation: These functions are not required any installation. These are the part of PHP core. The complete list of PHP string functions are given below: Example: This program helps us to calculate a 32-bit CRC for the string “Hello World”
6 min read
PHP Math Functions Complete Reference
The predefined math functions in PHP are used to handle the mathematical operations within the integer and float types. These math functions are part of the PHP core. Installation: These functions have not required any installation. The complete list of PHP math functions are given below: Example: Programs illustrate the decbin() function in PHP: C
3 min read
PHP Imagick Functions Complete Reference
The Imagick Function is used to create and modify images using the ImageMagick API. ImageMagick is the software suite to create edit and modify the composing bitmap images. Thisread, writes and converts images in many formats including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Requirements: PHP 5.1.3 and ImageMag
6 min read
PHP IntlChar Functions Complete Reference
IntlChar() functions provide access of utility methods which is used to access the information about Unicode characters. The IntlChar methods and constants are close to the names and behavior which are used by ICU (International Components for Unicode) library. Example: programs illustrate the IntlChar::charFromName() function in PHP C/C++ Code
4 min read
PHP ImagickDraw Functions Complete Reference
The ImagickDraw class is used to draw the vector-based image using ImageMagick. The vector-based generated image can be saved into the file. Syntax: bool ImagickDraw::s() Example: Below program illustrates the ImagickDraw::point() Function in PHP: C/C++ Code <?php // Create an ImagickDraw object $draw = new \ImagickDraw(); // Set the filled colo
3 min read
PHP Ds\Sequence Functions Complete Reference
A Sequence is used to arrange the values in a single and linear dimension way. In some languages, the sequence refers to the List. The sequence is similar to the array which is used as incremental integer keys are listed below: The index value of the sequence are [0, 1, 2, …, size - 1], where size represents the size of the array.The sequence eleme
3 min read
PHP Ds\Vector Functions Complete Reference
A Vector Data Structure is used to store the sequence of values in a contiguous memory buffer which grows and shrinks automatically. The vector data structure mapped the index value to its index buffer and the growth factor isn't bound to a specific multiple or exponent. It is the efficient Data Structure in PHP 7 to provide the alternative of an a
3 min read
PHP Ds\Stack Functions Complete Reference
Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). The Ds\Stack uses Ds\Vector internally. Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structur
2 min read
PHP Ds\Queue Functions Complete Reference
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: pub
2 min read
PHP DOM Functions Complete Reference
PHP DOM extension is used to operate on XML documents using DOM API. The DOM extension uses UTF-8 encoding. The Complete list of PHP DOM Functions are listed below: DOMAttr PHP DOMAttr __construct() FunctionPHP DOMAttr isId() Function DOMCdataSection PHP DOMCdataSection __construct() Function DOMCharacterData PHP DOMCharacterData appendData() Funct
2 min read
PHP intl Functions Complete Reference
The Complete list of PHP intl Functions are listed below: Collator PHP collator_asort() FunctionPHP collator_compare() FunctionPHP Collator __construct() FunctionPHP Collator create() FunctionPHP collator_sort_with_sort_keys() FunctionPHP collator_sort() Function IntlCalendar PHP IntlCalendar add() FunctionPHP IntlCalendar after() FunctionPHP IntlC
1 min read
PHP Ds\PriorityQueue toArray() Function
The Ds\PriorityQueue::toArray() Function in PHP is used to convert a PriorityQueue into an associative array in PHP. The values of the PriorityQueue are assigned to the array in order of decreasing priority. Syntax: array public Ds\PriorityQueue::toArray ( void ) Parameters: This function does not accepts any parameters. Return Value: This function
1 min read
PHP Ds\PriorityQueue push() Function
The Ds\PriorityQueue::push() Function in PHP is used to push or insert values in a PriorityQueue instance. This function pushes values along with a given priority in the PriorityQueue. Syntax: void public Ds\PriorityQueue::push($value, $priority) Parameters: This function accepts two parameters: $value: This is the value to be inserted in the Prior
1 min read
PHP Ds\PriorityQueue pop() Function
The Ds\PriorityQueue::pop() Function in PHP is used to remove and return the value present at the top of the PriorityQueue. In other words, it returns the value with the highest priority in the PriorityQueue and removes it. Syntax: mixed public Ds\PriorityQueue::pop ( void ) Parameters: This function does not accepts any parameters. Return Value: T
2 min read
PHP Ds\PriorityQueue count() Function
The Ds\PriorityQueue::count() Function in PHP is used to get the count of elements present in a Priority Queue instance. Syntax: int public Ds\PriorityQueue::count( void ) Parameters: This function does not accepts any parameters. Return Value: This function calculates the number of elements present in a Priority Queue instance and returns the coun
1 min read
PHP Ds\PriorityQueue isEmpty() Function
The isEmpty() Function of Ds\PriorityQueue class in PHP is used to whether a particular PriorityQueue instance is empty or not. It returns True if the PriorityQueue is empty otherwise it returns False. Syntax: bool isEmpty( ) Parameters: This function does not accepts any parameters. Return Value: This function returns a boolean value based on whet
1 min read
PHP Ds\PriorityQueue peek() Function
The Ds\PriorityQueue::peek() Function in PHP is used to get the value present at the front of a PriorityQueue. Syntax: mixed public Ds\PriorityQueue::peek ( void ) Parameters: This function does not accepts any parameters. Return Value: This function returns the value present at the front of this PriorityQueue. The return type of the function is mi
1 min read
PHP Ds\PriorityQueue copy() Function
The Ds\PriorityQueue::copy() Function in PHP is used to create a shallow copy of a particular PriorityQueue instance. This function does not affect the existing PriorityQueue instance, it just creates a shallow copy of the PriorityQueue and returns it. Syntax: Ds\PriorityQueue public Ds\PriorityQueue::copy ( void ) Parameters: This function does no
1 min read
PHP Ds\PriorityQueue clear() Function
The Ds\PriorityQueue::clear() Function in PHP is used to clear all of the elements from a PriorityQueue instance. This function just clears the instance without deleting it. Syntax: void public Ds\PriorityQueue::clear ( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not returns any value. Below pr
1 min read
PHP Ds\PriorityQueue capacity() Function
The Ds\PriorityQueue::capacity() Function in PHP is used to check the current capacity of a PriorityQueue instance. Syntax: int public Ds\PriorityQueue::capacity ( void ) Parameters: This function does not accepts any parameters. Return Value: This function returns the current capacity of the PriorityQueue instance. Below programs illustrate the Ds
1 min read
PHP Ds\PriorityQueue allocate() Function
The Ds\PriorityQueue::allocate() Function in PHP is used to allocate memory for a PriorityQueue class instance. This function allocates sufficient memory for a given capacity for an instance of PriorityQueue class. Syntax: void public Ds\PriorityQueue::allocate ( int $capacity ) Parameters: This function accepts a single parameter $capacity which i
2 min read
CSS Functions Complete Reference
CSS functions are used to set the various CSS property. For example, the attr() function is used to retrieve the value of the HTML attribute. Example: Below example illustrates the radial-gradient() function in CSS: C/C++ Code <!DOCTYPE html> <html> <head> <title>CSS Gradients</title> <style> #main { height: 250p
4 min read