Skip to content
Related Articles

Related Articles

PHP SplHeap isEmpty() Function
  • Last Updated : 23 Mar, 2021

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :