PHP SplHeap insert() Function Last Updated : 18 May, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The SplHeap::insert() function is an inbuilt function in PHP which is used to insert an element in the heap by sifting it 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 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: void SplHeap::insert( mixed $value ) Parameters: This function accept one parameter i.e. $value that is to be insert into the heap. Return Value: This function does not return any value. Below programs illustrate the SplHeap::insert() function in PHP: Example 1: PHP <?php // Create a new empty Min Heap $heap = new SplMinHeap(); // Inset elements in min heap $heap->insert('System'); $heap->insert('GFG'); $heap->insert('ALGO'); $heap->insert('C'); $heap->insert('Geeks'); $heap->insert('GeeksforGeeks'); // Loop to display the max heap elements 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(); // Insert elements in max heap $heap->insert('System'); $heap->insert('GFG'); $heap->insert('ALGO'); $heap->insert('C'); $heap->insert('Geeks'); $heap->insert('GeeksforGeeks'); // Loop to display the min heap elements for ($heap->top(); $heap->valid(); $heap->next()) { echo $heap->current() . "\n"; } ?> Output: System GeeksforGeeks Geeks GFG C ALGO Reference: https://www.php.net/manual/en/splheap.insert.php Comment More infoAdvertise with us Next Article PHP SplHeap isEmpty() Function A ashokjaiswal Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplHeap next() Function The SplHeap::next() function is an inbuilt function in PHP that is used to move to the next node. This will delete the top node of the heap. Generally, the Heap Data Structure is 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 2 min read 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 sam 2 min read PHP SplHeap key() Function The SplHeap::key() function is an inbuilt function in PHP which is used to get the current node index. 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 2 min read 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. T 2 min read PHP SplHeap top() Function The SplHeap::top() function is an inbuilt function in PHP that is used to display the peek node from the top of the heap. Generally, the Heap Data Structure is 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 s 2 min read PHP SplPriorityQueue insert() Function The SplPriorityQueue::insert() function is an inbuilt function in PHP which is used to inserts an element in the queue by sifting the elements. Insert elements in priority queue by given priority. Syntax: bool SplPriorityQueue::insert( mixed $value, mixed $priority ) Parameters: This function accept 2 min read Like