PHP | Ds\Stack count() Function
The Ds\Stack::count() function is an inbuilt function in PHP which is used to count the number of elements present in the Stack.
Syntax:
int Ds\Stack::count( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the number of elements present in the Stack.
Below programs illustrate the Ds\Stack::count() function in PHP:
Program 1:
<?php // Declare new stack $stack = new \Ds\Stack([10, 15, 21]); // Display the stack element var_dump($stack); // Count number of elements // present in the stack echo "Number of elements present in the stack: "; print_r($stack->count()); ?> |
object(Ds\Stack)#1 (3) {
[0]=>
int(21)
[1]=>
int(15)
[2]=>
int(10)
}
Number of elements present in the stack: 3
Program 2:
<?php // Declare new stack $stack = new \Ds\Stack(["Geeks", "for", "Keegs"]); // Display the stack element print_r($stack); // Display count of elements // present in the stack echo "Number of elements present in the stack: "; var_dump($stack->count()); ?> |
Ds\Stack Object
(
[0] => Keegs
[1] => for
[2] => Geeks
)
Number of elements present in the stack: int(3)
Reference: https://www.php.net/manual/en/ds-stack.count.php
Recommended Posts:
- PHP | count() Function
- PHP Ds\Set count() Function
- PHP | Ds\Map count() Function
- PHP | SimpleXMLElement count() Function
- PHP | Ds\Deque count() Function
- PHP | ArrayObject count() Function
- PHP | SplFixedArray count() Function
- PHP | SplHeap count() Function
- PHP Ds\Queue count() Function
- PHP | SplDoublyLinkedList count() function
- PHP | Ds\Vector count() Function
- PHP Ds\PriorityQueue count() Function
- PHP | SplObjectStorage count() Function
- How to call a function that return another function in JavaScript ?
- How to count files in a directory using PHP?
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.



