Thursday, September 4, 2025
HomeLanguagesPHP SplPriorityQueue current() Function

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 current node depending on the extract flag. 

 

Example:

PHP




<?php
  
// 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
$obj->insert("Geeks",2);
$obj->insert("GFG",1);
$obj->insert("G4G",3);
$obj->insert('G',4);
  
// Display the current element
// of priority queue
print_r($obj->current());
  
?>


Output

G

Reference: https://www.php.net/manual/en/splpriorityqueue.current.php

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS