PHP | SplFixedArray setSize() Function

The SplFixedArray::setSize() function is an inbuilt function in PHP which is used to set the size of the array.

Syntax:

bool SplFixedArray::setSize( $size )

Parameters: This function accepts a single parameter $size which specifies the size of the array.



Return Value: This function returns true on success, false otherwise.

Below programs illustrate the SplFixedArray::setSize() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create fixed size array
$gfg = new SplFixedArray(50);
  
// Print size before set
echo $gfg->getSize() . "\n";
  
// Set size of array 
$gfg->setSize(110);
  
// Print result after set the size
echo $gfg->getSize() . "\n";
?>

chevron_right


Output:

50
110

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create some fixed size array
$gfg1 = new SplFixedArray(0);
$gfg2 = new SplFixedArray(9);
$gfg3 = new SplFixedArray(100);
$gfg4 = new SplFixedArray(878);
   
// Print Size of the array
echo $gfg1->getSize() . "\n";
echo $gfg2->getSize() . "\n";
echo $gfg3->getSize() . "\n";
echo $gfg4->getSize() . "\n";
   
// Set array size
$gfg1->setSize(100);
$gfg2->setSize(200);
   
// Print size after set
echo $gfg1->getSize() . "\n";
echo $gfg2->getSize() . "\n";
?>

chevron_right


Output:

0
9
100
878
100
200

Reference: https://www.php.net/manual/en/splfixedarray.setsize.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.