The PHP manual states
“Generators provide an easy way to implement simple iterators without the overhead or complexity of implementing a class that implements the Iterator interface.”
The key to understating the way the yield works verses a normal function is that rather than generating all of your data and returning the final array when it’s done; you
yield the value as it’s generated. The state of the generator function is saved after you yield and then its state is restored when called again so the iteration can continue.
The most practical use case of generators I have found thus far is for skating around memory usage issues. If you’ve got a function that generates a large array that you need to iterate over via foreach generators are your ticket.