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
$stack = new \Ds\Stack([10, 15, 21]);
var_dump( $stack );
echo "Number of elements present in the stack: " ;
print_r( $stack -> count ());
?>
|
Output:
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
$stack = new \Ds\Stack([ "Geeks" , "for" , "Keegs" ]);
print_r( $stack );
echo "Number of elements present in the stack: " ;
var_dump( $stack -> count ());
?>
|
Output:
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 Jul, 2019
Like Article
Save Article