The Ds\Map::allocate() function is an inbuilt function in PHP which is used to allocate enough memory for required capacity.
Syntax:
void public Ds\Map::allocate( $capacity )
Parameters: 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\Map::allocate() function in PHP:
Program 1:
<?php
$map = new \Ds\Map();
var_dump( $map ->capacity());
$map ->allocate(50);
var_dump( $map ->capacity());
$map ->allocate(80);
var_dump( $map ->capacity());
?>
|
Output:
int(8)
int(64)
int(128)
Program 2:
<?php
$map = new \Ds\Map();
$arr = array (10, 20, 30, 40);
foreach ( $arr as $val ) {
$map ->allocate( $val );
var_dump( $map ->capacity());
}
?>
|
Output:
int(16)
int(32)
int(32)
int(64)
Reference: https://www.php.net/manual/en/ds-map.allocate.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
20 Aug, 2019
Like Article
Save Article