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
$gfg = new SplFixedArray(2);
$gfg [1] = "GeeksforGeeks" ;
var_dump( $gfg [0]);
var_dump( $gfg [1]);
?>
|
Output:
NULL
string(13) "GeeksforGeeks"
Program 2:
<?php
$gfg = new SplFixedArray(8);
$gfg [2] = 5;
$gfg [4] = "gfg" ;
$gfg [5] = "Geeks" ;
$gfg [7] = "GeeksforGeeks" ;
foreach ( $gfg as $i ) {
var_dump( $i );
}
?>
|
Output:
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
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 :
03 Oct, 2019
Like Article
Save Article