Php Iterable

An iterable is any value which can be looped through with a foreach() loop.

The iterable pseudo-type was introduced in PHP 7.1, and it can be used as a data type for function arguments and function return values.

Example

 1<?php
 2function printIterable(iterable $myIterable) {
 3  foreach($myIterable as $item) {
 4    echo "{$item}\n";
 5  }
 6}
 7
 8$arr = ["a", "b", "c"];
 9printIterable($arr);
10?>

This prints:

1a
2b
3c

Return an iterable:

 1<?php
 2function getIterable():iterable {
 3  return ["a", "b", "c"];
 4}
 5
 6$myIterable = getIterable();
 7foreach($myIterable as $item) {
 8  echo $item;
 9}
10?>

See details in https://www.w3schools.com/php/php_iterables.asp or https://www.php.net/manual/en/language.types.iterable.php