Hacker News new | ask | show | jobs
by tpetry 2037 days ago
You can do it very simple by writing a custom generator function:

foreach(myfunc($array) as list($key, $value, $loop)) {}

Maybe you can array destructuring at this place, i am not sure at the moment.

And your manual counting you do in myfunc() and just yield the values