PHP SplHeap __construct() Function Last Updated : 07 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The SplHeap::__construct() function is an inbuilt function in PHP that is used to create the heap data structure. 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: public SplHeap::__construct() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the SplMaxHeap::__construct() function in PHP: Example 1: PHP <?php // Create a new empty Min Heap $heap = new SplMinHeap(); $heap->insert('System'); $heap->insert('GFG'); $heap->insert('ALGO'); $heap->insert('C'); $heap->insert('Geeks'); $heap->insert('GeeksforGeeks'); // Loop to display the current element of heap for ($heap->top(); $heap->valid(); $heap->next()) { echo $heap->current() . "\n"; } ?> Output: ALGO C GFG Geeks GeeksforGeeks System Example 2: PHP <?php // Create a new empty Max Heap $heap = new SplMaxHeap(); $heap->insert('System'); $heap->insert('GFG'); $heap->insert('ALGO'); $heap->insert('C'); $heap->insert('Geeks'); $heap->insert('GeeksforGeeks'); // Loop to display the current element of heap for ($heap->top(); $heap->valid(); $heap->next()) { echo $heap->current() . "\n"; } ?> Output: System GeeksforGeeks Geeks GFG C ALGO Comment More infoAdvertise with us Next Article PHP SplQueue::__construct() Function A ashokjaiswal Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplQueue::__construct() Function The SplQueue::__construct() function is an inbuilt function in PHP which is used to construct a queue which is implemented using a doubly-linked list. Syntax: void SplQueue::__construct(void) Parameters: This function does not accept any parameter. Return Value: This function does not return any val 1 min read PHP | SplHeap count() Function The SplHeap::count() function is an inbuilt function in PHP which is used to count the elements in the heap. Generally, Heap can be 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 recursi 2 min read PHP SplHeap extract() Function The SplHeap::extract() function is an inbuilt function in PHP which is used to extract a node from top of the heap and sift up. 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 childre 1 min read PHP | SplFixedArray __construct() Function The SplFixedArray::__construct() function is an inbuilt function in PHP which is used to construct a new fixed size array. Syntax: void SplFixedArray::__construct( $size ) Parameters: This function accepts single parameter $size which specifies the size of an array. Return Value: This function does 1 min read PHP | SplHeap current() Function The SplHeap::current() function is an inbuilt function in PHP which is used to get the current element pointed by the iterator. 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 2 min read PHP | SplDoublyLinkedList __construct() Function The SplDoublyLinkedList::__construct() function is an inbuilt function in PHP which is used to create a new empty doubly linked list. Syntax: public SplDoublyLinkedList::__construct( void ) Parameters: This function does not accept any parameter. Return Value: This function does not return any value 1 min read Like