PHP | Ds\Stack capacity() Function

The Ds\Stack::capacity() function is an inbuilt function in PHP which is used to return the current capacity of the stack.

Syntax:

int Ds\Stack::capacity( void )

Parameters: This function does not accept any parameters.



Return Value: This function returns the current capacity of the stack.

Below programs illustrate the Ds\Stack::capacity() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Declare new Stack 
$stack = new \Ds\Stack(); 
  
// Use capacity() function to check
// the current capacity 
var_dump($stack->capacity()); 
  
?>

chevron_right


Output:

int(8)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Declare new Stack 
$stack = new \Ds\Stack(); 
  
echo("Current Capacity is: "); 
  
// Use capacity() function 
// to check the current capacity 
var_dump($stack->capacity()); 
  
echo("Current Capacity is: "); 
  
// Use allocate() function to 
// allocate capacity 
$stack->allocate(5); 
  
// Display the allocated vector 
// capacity 
var_dump($stack->capacity()); 
  
echo("Current Capacity is: ");
  
// Use allocate() function to 
// allocate capacity 
$stack->allocate(120); 
  
// Display the allocated vector 
// capacity 
var_dump($stack->capacity()); 
  
?> 

chevron_right


Output:

Current Capacity is: int(8)
Current Capacity is: int(8)
Current Capacity is: int(120)

Reference: https://www.php.net/manual/en/ds-stack.capacity.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.