Ds \ Vector::capacity()函数是PHP中的一个内置函数,用于返回向量的当前容量。
用法:
int public Ds\Vector::capacity( void )
参数:该函数不接受任何参数。
返回值:此函数返回向量的当前容量。
以下示例程序旨在说明PHP中的Ds \ Vector::capacity()函数:
程序1:
// 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());
?>
输出:
int(8)
int(20)
程序2:
// 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());
?>
输出:
int(8)
int(100)