PHP iterable

PHP Iterables Tutorial


Iterables were introduced in PHP 7.4 as pseudo-types. These are not actual types and are only used to represent items that may be iterated on, like arrays or objects.

Any item said to be an iterable can be iterated using the foreach loop.

Iterables can be used to define a function parameter’s type to indicate that whatever input is being passed must be a set of values that may be iterated on.

PHP - Using Iterables
The iterable keyword can be used as a data type of a function argument or as the return type of a function:

Example
Use an iterable function argument:

Output : abc

Example :Return an iterable

Output : abc