PHP | Ds\Vector capacity() Function

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

Syntax:

public Ds\Vector::capacity( void ) : int

Parameters: This function does not accept any parameter.

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

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare a vector
$vector = new \Ds\Vector();
  
// Use capacity() function to 
// find the vector capacity 
// and display it
var_dump($vector->capacity());
  
// Use push() function to add 
// vector element
$vector->push(...range(1, 20));
  
// Display the vector capacity
var_dump($vector->capacity());
  
?> 

chevron_right


Output:

int(8)
int(20)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare a vector
$vector = new \Ds\Vector();
  
// Use capacity() function to 
// find the vector capacity 
// and display it
var_dump($vector->capacity());
  
// Use push() function to add 
// vector element
$vector->push(...range(1, 100));
  
// Display the vector capacity
var_dump($vector->capacity());
  
?> 

chevron_right


Output:

int(8)
int(100)

Reference: http://php.net/manual/en/ds-vector.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.