PHP SplHeap key() Function Last Updated : 26 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 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::key() Parameters: This function does not accept any parameter. Return Value: This function returns the key of current node. Below programs illustrate the SplHeap::key() function in PHP: Example 1: PHP <?php // Create a new empty Mix 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 "Key => " . $heap->key() . ", Value => " . $heap->current() . "\n"; } ?> Output: Key => 5, Value => ALGO Key => 4, Value => C Key => 3, Value => GFG Key => 2, Value => Geeks Key => 1, Value => GeeksforGeeks Key => 0, Value => 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 with key for ($heap->top(); $heap->valid(); $heap->next()) { echo "Key => " . $heap->key() . ", Value => " . $heap->current() . "\n"; } ?> Output: Key => 5, Value => System Key => 4, Value => GeeksforGeeks Key => 3, Value => Geeks Key => 2, Value => GFG Key => 1, Value => C Key => 0, Value => ALGO Reference: https://www.php.net/manual/en/splheap.key.php Comment More infoAdvertise with us Next Article PHP SplHeap top() 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 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 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 SplFixedArray key() Function The SplFixedArray::key() function is an inbuilt function in PHP which is used to get the key of the current index of the array. Syntax: int SplFixedArray::key() Parameters: This function does not accept any parameter. Return Value: This function returns the key of the current index of the array. Bel 1 min read PHP key() Function The key() function is an inbuilt function in PHP which is used to return the index of the element of a given array to which the internal pointer is currently pointing. The current element may be starting or next element which depends on the cursor position. By default cursor position is at zero inde 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 Like