Thursday, October 23, 2025
HomeLanguagesPHP | ArrayIterator count() Function

PHP | ArrayIterator count() Function

The ArrayIterator::count() function is an inbuilt function in PHP which is used to count the elements of array iterator.
Syntax: 

int ArrayIterator::count( void )

Parameters: This function does not accept any parameters.
Return Value: This function returns the number of element present in the array iterator.
Below programs illustrate the ArrayIterator::count() function in PHP:
Program 1: 

php




<?php
  
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array('G', 'e', 'e', 'k', 's')
);
  
// Count the element into array iterator
echo $arrItr->count();
  
?>


Output: 

5

 

Program 2: 

php




<?php
  
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array("Geeks", "for", "Geeks"),
    ArrayIterator::STD_PROP_LIST
);
  
// Count the array element
echo $arrItr->count();
  
?>


Output: 

3

 

Reference: https://www.php.net/manual/en/arrayiterator.count.php 

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS