Open In App

PHP SplHeap isEmpty() Function

The SplHeap::isEmpty() function is an inbuilt function in PHP which is used to check whether the heap is empty or not.

Generally, the Heap Data Structure are of two types:



Syntax:

bool SplHeap::isEmpty()

Parameters: This function does not accept any parameter.



Return Value: This function returns whether the heap is empty. 

Below programs illustrate the SplHeap::isEmpty() function in PHP:

Example 1:




<?php 
  
// Create a new empty Max Heap 
$heap1 = new SplMaxHeap(); 
  
// Create a new empty Max Heap 
$heap2 = new SplMaxHeap(); 
  
// Insert elements in max heap
$heap2->insert('System'); 
$heap2->insert('GFG'); 
  
// Check heap is empty or not
var_dump($heap1->isEmpty());
  
var_dump($heap2->isEmpty());
  
?>

Output:

bool(true)
bool(false)

Example 2:




<?php 
  
// Create a new empty Min Heap 
$heap1 = new SplMinHeap(); 
  
// Create a new empty Max Heap 
$heap2 = new SplMinHeap(); 
  
// Insert elements in min heap
$heap2->insert('System'); 
$heap2->insert('GFG'); 
  
// Check heap is empty or not
var_dump($heap1->isEmpty());
  
var_dump($heap2->isEmpty());
  
?>

Output:

bool(true)
bool(false)

Reference: https://www.php.net/manual/en/splheap.isempty.php


Article Tags :