The SplPriorityQueue::isEmpty() function is an inbuilt function in PHP that is used to check whether the queue is empty or not.
Syntax:
bool SplPriorityQueue::isEmpty()
Parameters: This function does not accept any parameter.
Return Value: This function returns a boolean value either true or false depending upon the queue is empty or not.
Example 1:
PHP
<?php // Declare empty class class priorityQueue extends SplPriorityQueue {
} // Create an object of priority queue $obj = new priorityQueue();
// Use isEmpty() function to check // priority queue is empty or not var_dump( $obj ->isEmpty());
?> |
Output
bool(true)
Example 2:
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);
// Use isEmpty() function to check // priority queue is empty or not var_dump( $obj ->isEmpty());
?> |
Output
bool(false)
Reference: https://www.php.net/manual/en/splpriorityqueue.isempty.php