PHP SplHeap top() Function Last Updated : 24 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 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: mixed SplHeap::top() Parameters: This function does not accept any parameter. Return Value: This function returns the value of the node on the top. Below programs illustrate the SplHeap::top() function in PHP. Example 1: PHP <?php // Create a new empty Min Heap $heap = new SplMinHeap(); // Insert the elements into the heap $heap->insert('System'); $heap->insert('GFG'); $heap->insert('ALGO'); $heap->insert('C'); $heap->insert('Geeks'); $heap->insert('GeeksforGeeks'); // Display the top element var_dump($heap->top()); ?> Output: string(4) "ALGO" Example 2: PHP <?php // Create a new empty Max Heap $heap = new SplMaxHeap(); $heap->insert('System'.'<br/>'); $heap->insert('GFG'.'<br/>'); $heap->insert('ALGO'.'<br/>'); $heap->insert('C'.'<br/>'); $heap->insert('Geeks'.'<br/>'); $heap->insert('GeeksforGeeks'.'<br/>'); // 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 Reference: https://www.php.net/manual/en/splheap.top.php Comment More infoAdvertise with us Next Article PHP | SplHeap count() Function A ashokjaiswal Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplHeap valid() Function The SplHeap::valid() function is an inbuilt function in PHP which is used to check whether the heap contains more nodes. 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 s 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 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 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 rewind() Function The SplHeap::rewind() function is an inbuilt function in PHP that is used to rewind the iterator to the beginning. 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 pr 2 min read PHP SplHeap insert() Function 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. 2 min read Like