3 ms·
What's idiomatic way to get index (0, n-1) with the value? Parent example shows you could not use $key as a generic solution.
by bvrmn 1y ago
What's idiomatic way to get index (0, n-1) with the value? Parent example shows you could not use $key as a generic solution.
- doekenorg 1y agoYou can use the SPL LimitIterator, feed it the generator, and give it the offset and limit. ``` foreach (new LimitIterator($generator, 0, 3) as $value) { echo $value; } ``` https://www.php.net/manual/en/class.limititerator.php https://www.php.net/manual/en/class.limititerator.php