• PHP Video Tutorials

PHP - Ds\Stack::count() Function



Ds\Stack::count() function can be used to count the number of elements present in a stack.

Syntax

int Ds\Stack::count( void )

Ds\Stack::count() function doesn't have any parameters.

Ds\Stack::count() function can return the number of values in a stack.

Example-1

<?php  
   $stack = new \Ds\Stack([1, 4, 5, 7, 9, 10]);  
   var_dump($stack);  
   
   echo "The number of elements present in a stack:";  
   print_r($stack->count());  
?>

Example-2

<?php  
   $stack = new \Ds\Stack(["Tutorials", "Point", "India"]);  
   print_r($stack);  
  
   echo "The number of elements present in a stack:";  
   var_dump($stack->count());  
?>
php_function_reference.htm
Advertisements