Open In App

PHP | Ds\Vector capacity() Function

Improve
Improve
Like Article
Like
Save
Share
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
  
// 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
  
// 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



Last Updated : 22 Aug, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads