Open In App

PHP | Ds\Vector capacity() Function

Last Updated : 22 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The Ds\Vector::capacity() function is an inbuilt function in PHP which is used to return the current capacity of the vector. Syntax:
int public Ds\Vector::capacity( void )
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: PHP
<?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());

?> 
Output:
int(8)
int(20)
Program 2: PHP
<?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());

?> 
Output:
int(8)
int(100)
Reference: http://php.net/manual/en/ds-vector.capacity.php

Next Article

Similar Reads