Sunday, November 16, 2025
HomeLanguagesPHP SplHeap isCorrupted() Function

PHP SplHeap isCorrupted() Function

The SplHeap::isCorrupted() function is an inbuilt function in PHP which is used to tell if the heap is in a corrupted state.

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::isCorrupted()

Parameters: This function does not accept any parameter.

Return Value: This function returns true if the heap is corrupted, false otherwise.

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

Example 1:

PHP




<?php 
  
// Create a new empty Mix Heap 
$heap = new SplMinHeap(); 
  
// Insert elements in min heap
$heap->insert('System'); 
$heap->insert('GFG'); 
$heap->insert('ALGO'); 
$heap->insert('C');
$heap->insert('Geeks'); 
$heap->insert('neveropen'); 
  
// Check heap is in a corrupted
// state or not
var_dump($heap->isCorrupted());
  
?>


Output:

bool(false)

Example 2:

PHP




<?php 
  
// Create a new empty Max Heap 
$heap = new SplMaxHeap(); 
  
// Insert elements in max heap
$heap->insert('System'); 
$heap->insert('GFG'); 
$heap->insert('ALGO'); 
$heap->insert('C');
$heap->insert('Geeks'); 
$heap->insert('neveropen'); 
  
// Check heap is in a corrupted
// state or not
var_dump($heap->isCorrupted());
  
?>


Output:

bool(false)

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

RELATED ARTICLES

Most Popular

Dominic
32402 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6768 POSTS0 COMMENTS
Nicole Veronica
11919 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11990 POSTS0 COMMENTS
Shaida Kate Naidoo
6897 POSTS0 COMMENTS
Ted Musemwa
7149 POSTS0 COMMENTS
Thapelo Manthata
6850 POSTS0 COMMENTS
Umr Jansen
6841 POSTS0 COMMENTS