That’s interesting as I haven’t played with iterates and generators much. 

If the iterator can’t take an iterable, the idea of something like __toArray 
seems way more convenient: https://wiki.php.net/rfc/to-array

Cheers,
Josh

> On Aug 31, 2020, at 4:39 PM, Michael Voříšek - ČVUT FEL 
> <voris...@fel.cvut.cz> wrote:
> 
> I would highly prefer php optimalization for it. ArrayKeysIterator can
> not even used if the input is iterable instead of pure array. 
> With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem,
> 
> Michael Voříšek
> 
>> On 31 Aug 2020 23:31, Max Semenik wrote:
>> 
>>> On Mon, Aug 31, 2020 at 11:53 PM Michael Voříšek - ČVUT FEL 
>>> <voris...@fel.cvut.cz> wrote: 
>>> Optimizing foreach (array_keys($arr) as $k) is very important, not only
>>> because of memory, but because of speed when not all elements needs to
>>> be iterated, like: foreach (array_keys($arr) as $k) { if ($k some 
>>> condition) { break; } }
>> Can an iterator be the answer? E.g. foreach (new ArrayKeysIterator($arr) as 
>> $k) { ... } --
>> Best regards,
>> Max Semenik

Reply via email to