Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

iterator_count() Also Count Arrays

The PHP native function used to accept only iterators. Since PHP 8.1, arrays are also welcomed.

PHP code

<?php

print iterator_count([1,2,3]);

?>

Before

Uncaught TypeError: iterator_count(): Argument #1 ($iterator) must be of type Traversable, array given

After

3

PHP version change

This behavior changed in 8.2.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat