PHP Ds\PriorityQueue pop() Function Last Updated : 23 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: This function returns the value with the highest priority in this PriorityQueue and removes it. The return type of the function is mixed and depends on the type of value stored in the PriorityQueue. Exception: This function throws an UnderflowException if the PriorityQueue is empty. Below programs illustrate the Ds\PriorityQueue::pop() Function in PHP: Program 1: 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); echo "Initial PriorityQueue is: \n"; print_r($pq); // Pop an element echo "\nPopped element is: "; print_r($pq->pop()); echo "\n\nFinal PriorityQueue is: \n"; print_r($pq); ?> Output: Initial PriorityQueue is: Ds\PriorityQueue Object ( [0] => Three [1] => Two [2] => One ) Popped element is: Three Final PriorityQueue is: Ds\PriorityQueue Object ( [0] => Two [1] => One ) Program 2: php <?php // Declare new PriorityQueue $pq = new \Ds\PriorityQueue(); // Add elements to the PriorityQueue $pq->push("One", 1); $pq->push("Two", 3); $pq->push("Three", 2); echo "Initial PriorityQueue is: \n"; print_r($pq); // Pop an element echo "\nPopped element is: "; print_r($pq->pop()); echo "\n\nFinal PriorityQueue is: \n"; print_r($pq); ?> Output: Initial PriorityQueue is: Ds\PriorityQueue Object ( [0] => Two [1] => Three [2] => One ) Popped element is: Two Final PriorityQueue is: Ds\PriorityQueue Object ( [0] => Three [1] => One ) Reference: http://php.net/manual/en/ds-priorityqueue.pop.php Comment More infoAdvertise with us Next Article PHP SplPriorityQueue compare() Function G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_priorityqueue Similar Reads PHP SplPriorityQueue key() Function The SplPriorityQueue::key() function is an inbuilt function in PHP that is used to return the current node index. Syntax: mixed SplPriorityQueue::key() Parameters: This function does not accept any parameter. Return Value: This function returns the current node index. Example: PHP <?php // Declar 1 min read PHP SplPriorityQueue count() Function The SplPriorityQueue::count() function is an inbuilt function in PHP which is used to count the number of elements in the queue. Syntax: int SplPriorityQueue::count() Parameters: This function does not accept any parameters. Return Value: This function returns the number of elements in the queue. Ex 1 min read PHP SplPriorityQueue next() Function The SplPriorityQueue::next() function is an inbuilt function in PHP that is used to extract the top node from the queue. Syntax: void SplPriorityQueue::next() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Example: PHP <?php // Decl 1 min read PHP SplPriorityQueue current() Function The SplPriorityQueue::current() function is an inbuilt function in PHP which is used to return the current node pointed by the iterator. Syntax: mixed SplPriorityQueue::current() Parameters: This function does not accept any parameter. Return Value: This function returns the value/priority of the cu 1 min read PHP SplPriorityQueue compare() Function The SplPriorityQueue::compare() function is an inbuilt function in PHP which is used to compare the priority queue elements to place at a particular order in the heap data structure. Syntax: int SplPriorityQueue::compare( mixed $priority1 , mixed $priority2 ) Parameters: This function accepts two pa 2 min read PHP SplPriorityQueue extract() Function The SplPriorityQueue::extract() function is an inbuilt function in PHP which is used to extract a node from top of the heap and sift up. Syntax: mixed SplPriorityQueue::extract() Parameters: This function does not accept any parameter. Return Value: This function returns the value/priority (or both) 1 min read Like