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
> wrote:
Hi Riikka Kalliomäki,
> Another similar problem with creating array copies is the detection of
> "indexed" arrays (as opposed to associative arrays). Particularly when
> dealing with JSON, it's a common need to detect if an array has keys
> from 0 to n-1 and in that order. My understanding is that
Hi Riikka,
> On Aug 31, 2020, at 14:13, Riikka Kalliomäki
> wrote:
>
> A common pattern that I've seen that could dearly use PHP internal
> optimization, if possible, would be:
>
> foreach (array_keys($array) as $key) {
> }
I have a draft RFC (https://wiki.php.net/rfc/foreach_void) and patch
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
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) {
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;
}
}
please, can someone send a PR for this?
NB: You have SplFixedArray which can cover some use-cases.
On Mon, 31 Aug 2020, 20:48 Markus Fischer, wrote:
> On 31.08.20 20:13, Riikka Kalliomäki wrote:
> > Another similar problem with creating array copies is the detection of
> > "indexed" arrays (as opposed to associative arrays).
>
> I'm l
On 31.08.20 20:13, Riikka Kalliomäki wrote:
Another similar problem with creating array copies is the detection of
"indexed" arrays (as opposed to associative arrays).
I'm looking forward to an answer from someone proficient in this area
because _I think_ the engine _internally_ keeps track of