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:
abstract public Ds\Sequence::allocate( $capacity ) : void
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\Sequence::allocate() function in PHP:
Example 1:
<?php // Create new sequence $seq = new \Ds\Vector(); // Use capacity() function to // display the capacity var_dump($seq->capacity()); // Allocate capacity $seq->allocate(50); // Display capacity var_dump($seq->capacity()); // Allocate capacity $seq->allocate(80); // Display capacity var_dump($seq->capacity()); ?> |
Output:
int(8) int(50) int(80)
Example 2:
<?php // Create new sequence $seq = new \Ds\Vector(); // Declare capacity array $arr = array(10, 20, 30, 40); // Loop run for every array element foreach ($arr as $val) { // Allocate capacity $seq->allocate($val); // Display capacity var_dump($seq->capacity()); } ?> |
Output:
int(10) int(20) int(30) int(40)
Reference: http://php.net/manual/en/ds-sequence.allocate.php
Recommended Posts:
- PHP | Ds\Map allocate() Function
- PHP | Ds\Set allocate() Function
- PHP | Ds\Vector allocate() Function
- PHP | Ds\Stack allocate() Function
- PHP Ds\PriorityQueue allocate() Function
- PHP Ds\Queue allocate() Function
- PHP | Ds\Deque allocate() Function
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- p5.js | str() function
- D3.js | d3.max() function
- p5.js | cos() function
- p5.js | max() function
- PHP | pow( ) Function
- p5.js | hex() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



