Skip to content
Related Articles

Related Articles

PHP SplPriorityQueue next() Function

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

The SplPriorityQueue::next() function is an inbuilt function in PHP that is used to extract the top node from the queue. 


void SplPriorityQueue::next()

Parameters: This function does not accept any parameter.

Return Value: This function does not return any value.




// 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
// Loop to print the priority
// queue elements
    // Print the current element
    echo $obj->current() . " ";
    // Move to next element of
    // priority queue


G G4G Geeks GFG 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!