Open In App
Related Articles

PHP | ArrayIterator count() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

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 

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 : 14 Jan, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials