Open In App
Related Articles

PHP SplPriorityQueue count() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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. 

 

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 number of elements
// in priority queue
print_r($obj->count());
  
?>

                    

Output
4

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


Last Updated : 22 Apr, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads