What are Iterables in PHP and why do we use it?

I just heard about Iterables from the PHP 7.1 docs. But I didn't have my actual use case and I don't understand the concept. so can anyone explain this with a simple example to get a quick grasp on it?

I want to know why and where do we use it? What are the benefits of iteration?

+3


source to share


1 answer


This might help wiki.php.net/rfc/iterable



The main advantage iterable

is that a class, method, or function parameter can be declared iterable

but not implementation-specific, i.e. array, Iterator, Generator, etc. Thus, whatever is iterable

, can.

+1


source







All Articles