PHP 8.3.4 Released!

Iterables

Iterable is a built-in compile time type alias for array|Traversable. From its introduction in PHP 7.1.0 and prior to PHP 8.2.0, iterable was a built-in pseudo-type that acted as the aforementioned type alias and can be used as a type declaration. An iterable type can be used in foreach and with yield from within a generator.

Note:

Functions declaring iterable as a return type may also be generators.

Example #1 Iterable generator return type example

<?php

function gen(): iterable {
yield
1;
yield
2;
yield
3;
}

?>

add a note

User Contributed Notes 1 note

up
0
tehfahmy at gmail dot com
11 hours ago
When I type the word "iterable" in the search bar and press enter, it takes me to the function list instead of searching the whole site. I'm not challenging this implementation, but it takes more actions to find the page I want. Part of the reason I don't read docs is because of implementations like these which make it more difficult than necessary to find the information I'm looking for.

Consider this feedback and delete it if you want.
To Top