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 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.
Note: This article uses Max Heap which extends the SplHeap class.
Syntax:
int SplMaxHeap::count()
Parameters: This function does not accept any parameter.
Return Value: This function returns the number of nodes present in heap.
Below programs illustrate the SplMaxHeap::count() function in PHP:
Program 1:
<?php // Create a new empty Max Heap $heap = new SplMaxHeap(); $heap->insert('GEEKS'); $heap->insert('gfg'); // Print Result echo $heap->count(); ?> |
2
Program 2:
<?php // Create a new empty Max Heap $heap = new SplMaxHeap(); // Print Result echo $heap->count() . "\n"; $heap->insert('GEEKS'); $heap->insert('gfg'); $heap->insert('DSA'); $heap->insert('ALGO'); $heap->insert('C'); // Print Result echo $heap->count(); ?> |
0 5
Reference: https://www.php.net/manual/en/splheap.count.php
Recommended Posts:
- PHP | SplHeap current() Function
- PHP | Ds\Map count() Function
- PHP Ds\Set count() Function
- PHP | count() Function
- PHP Ds\Queue count() Function
- PHP | SplFixedArray count() Function
- PHP | SimpleXMLElement count() Function
- PHP | SplObjectStorage count() Function
- PHP | Ds\Deque count() Function
- PHP | SplDoublyLinkedList count() function
- PHP | ArrayIterator count() Function
- PHP | Ds\Stack count() Function
- PHP | ArrayObject count() Function
- PHP Ds\PriorityQueue count() Function
- PHP | Ds\Vector count() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


