Re: Request for couple memory optimized array improvements
| From: | Max Semenik | Date: | Mon, 31 Aug 2020 21:31:01 +0000 |
| Subject: | Re: Request for couple memory optimized array improvements | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111752@lists.php.net to get a copy of this message | ||
On Mon, Aug 31, 2020 at 11:53 PM Michael Voříšek - ČVUT FEL <
vorismi3@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