Skip to content
Related Articles

Related Articles

PHP SplPriorityQueue extract() Function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 22 Apr, 2021

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.


mixed SplPriorityQueue::extract()

Parameters: This function does not accept any parameter.

Return Value: This function returns the value/priority (or both) of the extracted node depending on the extract flag. 




// Declare a class
class priorityQueue extends SplPriorityQueue {
    // Compare function to compare priority
    // queue elements
    public function compare($p1, $p2) {
        if ($p1 === $p2) return 0;
        return $p1 < $p2 ? -1 : 1;
// Create an object of priority queue
$obj = new priorityQueue();
// Insert elements into the queue
// Display the extracted element
// from priority queue


string(1) "G"


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!