PHP | SplFixedArray count() Function

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

Syntax:

int SplFixedArray::count()

Parameters: This function does not accept any parameter.



Return Value: This function returns the size of the array.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an array of fixed size 10
$array = new SplFixedArray(10);
  
// Print size of the array
echo $array->count();
?>

chevron_right


Output:

10

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Creating fixed size array
$gfg = new SplFixedArray(8);
$gfg1 = new SplFixedArray(7);
$gfg2 = new SplFixedArray(9);
$gfg3 = new SplFixedArray(100);
$gfg4 = new SplFixedArray(878);
$gfg5 = new SplFixedArray(0);
  
// Print size of the array
echo $gfg1->count(). "\n";
echo $gfg2->count(). "\n";
echo $gfg3->count(). "\n";
echo $gfg4->count(). "\n";
  
// Count function can be used
// via passing parameters
echo count($gfg5) . "\n";
echo count($gfg) . "\n";
?>

chevron_right


Output:

7
9
100
878
0
8

Reference: https://www.php.net/manual/en/splfixedarray.count.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.