Tuesday, October 7, 2025
HomeLanguagesPHP SplHeap isEmpty() Function

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:

  • Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of its children. The same property must be recursively true for all sub-trees in that Binary Tree.
  • Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of its children. The same property must be recursively true for all sub-trees in that Binary Tree.

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




<?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




<?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

RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6829 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS