PHP iterator_count() Function Last Updated : 22 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The iterator_count() function is an inbuilt function in PHP that is used to count the number of elements in an iterator. An iterator is an object that is a collection of elements. Syntax: iterator_count(Traversable $iterator) : intParameters: This function accepts only one parameter which is described below. $iterator: The iterator for which you want to count the number of elements. This should be an object that implements the traversable interface, such as an array or an instance of a class that implements iterator or IteratorAggregate.Return Value: The iterator_count() function returns the number of elements in the iterator if this function successfully executes. Program 1: The following program demonstrates the iterator_count() function. PHP <?php $numbers = [1, 2, 3, 4, 5]; $iterator = new ArrayIterator($numbers); $numElements = iterator_count($iterator); echo "Total elements in the iterator: $numElements"; ?> OutputTotal elements in the iterator: 5 Program 2: The following program demonstrates the iterator_count() function. PHP <?php // Sample string $text = "GeeksforGeeks"; $iterator = new ArrayIterator(str_split($text)); // Count the total number of characters // in the string $numCharacters = iterator_count($iterator); echo "Total number of characters in the string: $numCharacters"; ?> OutputTotal number of characters in the string: 13 Reference: https://www.php.net/manual/en/function.iterator-count.php Comment More infoAdvertise with us Next Article PHP iterator_to_array() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-SPL-Functions Similar Reads PHP iterator_apply() Function The iterator_apply() function is an inbuilt function in PHP that is used to apply a user-defined callback function to each element of an iterator. It allows you to iterate any element without using any kind of loop. Syntax: int iterator_apply( Traversable $iterator, callable $callback, ?array $args 2 min read PHP count() Function The count() function in PHP is used to count the number of elements in an array or the countable properties of an object. The function returns an integer value representing the number of items present.Syntax:count($array, mode)In this syntax:$array (mandatory): Refers to the array, whose elements ar 3 min read PHP | is_countable() Function The is_countable() function is an inbuilt function in PHP which is used to check whether the content of the variable is countable or not. Syntax: bool is_countable ( mixed $var ) Parameters: This function accepts one parameter as mentioned above and described below: $var: This parameter holds the va 1 min read PHP iterator_to_array() Function The iterator_to_array() function is an inbuilt function in PHP that is used to copy the iterator object (e.g. objects implementing the Iterator or IteratorAggregate interface) into an array. An iterator is an object that allows you to loop through a set of values one at a time without knowing the un 3 min read ArrayObject getIterator() Function in PHP The getIterator() function of the ArrayObject class in PHP is used to create an iterator from an ArrayObject instance. This iterator can be used to iterate through the array of the respective ArrayObject. Syntax: ArrayIterator getIterator() Parameters: This function does not accepts any parameters. 1 min read PHP | SplHeap count() Function The SplHeap::count() function is an inbuilt function in PHP which is used to count the elements in the heap. Generally, Heap can be of two types: Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of its children. The same property must be recursi 2 min read Like