PHP | Ds\Sequence allocate() Function
The Ds\Sequence::allocate() function is an inbuilt function in PHP which is used to allocate enough memory for required capacity.
Syntax:
void abstract public Ds\Sequence::allocate ( int $capacity )
Parameter: This function accepts single parameter $capacity which indicate number of capacity allocated.
Return value: This function does not return any values.
Below programs illustrate the Ds\Sequence::allocate() function in PHP:
Example 1:
<?php
$seq = new \Ds\Vector();
var_dump( $seq ->capacity());
$seq ->allocate(50);
var_dump( $seq ->capacity());
$seq ->allocate(80);
var_dump( $seq ->capacity());
?>
|
Output:
int(8)
int(50)
int(80)
Example 2:
<?php
$seq = new \Ds\Vector();
$arr = array (10, 20, 30, 40);
foreach ( $arr as $val ) {
$seq ->allocate( $val );
var_dump( $seq ->capacity());
}
?>
|
Output:
int(10)
int(20)
int(30)
int(40)
Reference: http://php.net/manual/en/ds-sequence.allocate.php
Last Updated :
21 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...