Re: Array spread append
| From: | Vorisek, Michael | Date: | Thu, 06 Apr 2023 20:51:55 +0000 |
| Subject: | Re: Array spread append | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119828@lists.php.net to get a copy of this message | ||
The goal is fast multi-item array append, which is currently not possible, as
+= and
array_push operators does something else and array_merge is very slow as
the whole array is copied.
Currently the fastest approach is to use the foreach equivalent, which requires much more code and
two intermediate variables for k/v.
For better understanding, I have updated the example codes in https://github.com/php/php-src/issues/10791
but sadly all short codes are slow as array is copied.
Michael
________________________________
From: Michał Marcin Brzuchalski <michal.brzuchalski@gmail.com>
Sent: Thursday, April 6, 2023 5:01 PM
To: Vorisek, Michael <vorismi3@fjfi.cvut.cz>
Cc: PHP internals <internals@lists.php.net>
Subject: Re: [PHP-DEV] Array spread append
czw., 6 kwi 2023, 13:53 użytkownik Vorisek, Michael <vorismi3@fjfi.cvut.cz<mailto:vorismi3@fjfi.cvut.cz>> napisał:
Hi Ilija,
* Are integer keys preserved? I'm assuming no, as otherwise it would
be the same as $a + $b.
$arr[...] = $arr;
should be the same as
foreach ($arr as $v) { $arr[] = $v; }
I'd argue with that because I think the spread operator should be consistent with preserve keys
strategy used in other places.
Cheers,
Michał Marcin Brzuchalski