DEV Community

Programming Dive
Programming Dive

Posted on • Edited on

Generators in PHP

PHP 5.5 came up with an interesting function to the PHP ecosystem and that was Generators. So while using generators in PHP, we’ll see what are generators and what are different ways of using it.

The structure of generators are similar to the normal functions itself. But in generators instead of return statement, we use yield. Weird, right?. Basically this how generators need to be defined.

So, generators basically loops through an data and avoids large amount of memory for that Array. Yes, generators works with an Array and while creating new array out of the loops it avoids utilizing large amount of memory.

https://programmingdive.com/using-generators-in-php/

Top comments (0)