PHP | SplFixedArray __construct() Function
The SplFixedArray::__construct() function is an inbuilt function in PHP which is used to construct a new fixed size array.
Syntax:
void SplFixedArray::__construct( $size )
Parameters: This function accepts single parameter $size which specifies the size of an array.
Return Value: This function does not return any value.
Below programs illustrate the SplFixedArray::__construct() function in PHP:
Program 1:
<?php // Create new fixed array of size 2 $gfg = new SplFixedArray(2); $gfg[1] = "GeeksforGeeks"; // Print Result var_dump($gfg[0]); var_dump($gfg[1]); ?> |
NULL string(13) "GeeksforGeeks"
Program 2:
<?php // Create new fixed array of size 8 $gfg = new SplFixedArray(8); $gfg[2] = 5; $gfg[4] = "gfg"; $gfg[5] = "Geeks"; $gfg[7] = "GeeksforGeeks"; // Iterate array and print its values foreach( $gfg as $i ) { var_dump($i); } ?> |
NULL NULL int(5) NULL string(3) "gfg" string(5) "Geeks" NULL string(13) "GeeksforGeeks"
Reference: https://www.php.net/manual/en/splfixedarray.construct.php
Recommended Posts:
- PHP | SplFixedArray next() Function
- PHP | SplFixedArray key() Function
- PHP | SplFixedArray count() Function
- PHP | SplFixedArray current() Function
- PHP | SplFixedArray offsetExists() Function
- PHP | SplFixedArray offsetGet() Function
- PHP | SplFixedArray setSize() Function
- PHP | SplFixedArray toArray() Function
- PHP | SplFixedArray valid() Function
- PHP | SplFixedArray getSize() Function
- PHP | SplFixedArray offsetUnset () Function
- PHP | SplFixedArray rewind() Function
- What is the difference between a language construct and a “built-in” function in PHP ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
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.
Improved By : shubham_singh



