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:
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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



