Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130130 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id DD7031A00BC for ; Sun, 22 Feb 2026 19:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771787107; bh=6SzqdmTvTHttxl+uManj8QNcgaE+5HTKTezhtnE+Grk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nJOKrFCG9UfpePYGnzHmAoY69xxfCynu523FGz4k0juds8FsTwD7VYBi/4fA6UpUe hLrNxUUAoJ7E0k6W5+TbIoWT6GT81hmIUjbQTt9PFQIY5gJfEWSc/NqeOf53SZIwPs kqXa3r8dM7h9vQjXj5hr4K5rHGeuUHs+vZrl7tG/Tu3Upyasxv2r93OcaKr2YYzCqS im0G+dUls9iSi1V8FwQOSr3NYpmn/LDxlJM5REZj1XhPCYBNPLZgxM+IqQtK4onGBh E13c9fJPOLGEwB1udmtSIJfoX9pArUkquZkFd40VU00mQqKKnkMv5A19PvlRoXVDsO MuuWWoLifwL7A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 81D4418004F for ; Sun, 22 Feb 2026 19:05:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 22 Feb 2026 19:05:06 +0000 (UTC) Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-2b86671f87eso7369754eec.0 for ; Sun, 22 Feb 2026 11:05:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771787100; cv=none; d=google.com; s=arc-20240605; b=Th1TQ6V+CrA6itLZcNYGy/LuoKBvnygp+sDQCjGMXE+vnBs58miVv41R8gsFBu5clm zcWJRtq7B+AbSBarzTjIRFMd76YCRgQB6VzbPa766HYQeaD2ceTjxuEc78jwziKQ6Iqs SDNuq6IHGKjRAaoxzXFq41tui2Vd8miVL8yPmWbhURwUmla7kRn6nUvDMuW1wcFLcl6s u3RRvafte5IddMnWhn7Ru3yNHGH0yeh8xK4/rgLdUAS3WKRZFwit5IdIivNZQ763Q1Le Z8VFgrv05A8MFV2cRMDlzdV/VFroA+G2k7KL4VYfOyhQA+MBtm7km1/Z/nPmJJOPTOdV 3gmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=QgT0hDAXRnOQlB0J0OvaTlfgF/4imEYDJKyy94xAgY4=; fh=ZBhzV4cRMfMjA8HNjlYOEXEifVtKmu261g6CQRIDODk=; b=E9Oy9jKCong1fzfnuspCd4opIzK1JGNLKruzYYRjCBswzLCBSX19mrQs6vxhk+iUr9 TYS5dedLsAvLV/WJv8XIVB/rHYd31LaJh+FcTl35S8X2a/NWl+tLFfYWcdA7D7NCedQJ 1tlAXMt852iaYTPu+exWCPpMykVXWzXAk8XvgUX8d5Hh5yz+MllXZKDjrCrdH/AVbseT BadQBKNnwVz96gtZUdszlGAWcy93kr5bnNczCqvTgfma9LgS96der/KqAx4Lx53BVxuP HJmOgttqZ80+Grs+hHnnoEMd0HHeShnHN858QyNaz3GQku1KPTA1nJqxMtXgfJvAGQXR jcfw==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771787100; x=1772391900; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QgT0hDAXRnOQlB0J0OvaTlfgF/4imEYDJKyy94xAgY4=; b=EwmHXFqaF2GBDdY+ZX6XON0MNkVH1HGGSeNYDE0jeWuWW2ls7A4Wh+PZSlwKhRS08t XED0BVHZmAgQxCe5WIzoLWRwmshjJrNhdFHZK1lOomlVUkqVlFFsnDqdq1KT2639Sfku xDU9M4HcbJM4WBPTA48wNfOZ7iTmdroQSsQzkYK2Zd7Iqg/2eYNWQuZtNKyI1jn0fdtB ZltpEsLqEiE6Fw2ZuI/i7BnFcH7AcpxmbIZiIvwKiL5KP+JbxEiP9J5NDfSX0rGNkeG2 R7VSMAEPnLinzBlIckM5BNmqAzlpBIevIjojOlHcZ4JQeddAM8V/F/VH+fbcwcBYAAuo XYCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771787100; x=1772391900; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QgT0hDAXRnOQlB0J0OvaTlfgF/4imEYDJKyy94xAgY4=; b=Ym0Vj6oz00wyEiXRsP7aVskSkVvWW1allaIOqvMnagzht9rfUaqSK/SAk+cTy7g1MM Po6yUKhWURHOdiTf9VL4OV5BV1mYAPc9U11k6gQXJ+eWDfMJDscAs9sKLfTtugTvikJG +YQ/RzU2wKGVDX+Q2+7FSuA2G04rr7yEyHUJ2HPmwA7NaTLRHMxcQMzqrbM/YV9BkuEV IwYDVbsqK3ZuGjSc+9eu9H74jK5++Gg8VVYsWZJwzBx92wj8tKx9/mtzv0WDMPMvrnyF efAlv/NW1kYHjcNCIIzC7vvMyZcZoWmX/QNXfw5JeGw2oKpM6DqyxadJxwAVnKg0Mms/ uGFg== X-Forwarded-Encrypted: i=1; AJvYcCUdSxqg/VaHnBIvvAeJv4PS+DfsK2GclAaW3HAcoQW0iHHsMNz3fkzC+ctqut3Dyn+FAHBQKBxozJw=@lists.php.net X-Gm-Message-State: AOJu0YxgtMbmEQbyD7nKbshQO1qLqcrDXlsLybrR5qoSzf0CSDacqcfC qsZpDy3ZUxXobmUL75Iomxxe2/IyiNRnYTVOQn/NxMOz+InbX73oL5meYQMcieEB148KnIP09kA OM8/VZn7QS0rcpS2jKK6lgb4qpB8VnPaEhw== X-Gm-Gg: AZuq6aJrBsJEJ/Opt5MBCOVs8IMgzpO/1BXyfYePzrPGmoxP4jDuvP+e3aACq7MuD+l MoDFT32zyR8jLupgSAqzvXLdTE5u7nw5n/ztn6qH3RtFK7p14SYLxVu9PGVtWjnpZzumO6e115a 5m/r4Sm6zAFzj2KcaHT2i2s7oDv5/4KzrH2zQuRoj7sW4NdbH4xnxcYO45V/x47+m+qFSefp2vL d0kSLfPfQNpUY5yMhW1rBzqTy6tbCzYy9ZvCjTCw4n+N/l9LZZfD8jbnGO+rlwJGEYyUPEqKt2O agKJ1Bm1232UJwCi2DJVaBnNGsF9fP6tVN3t/Fq1elPtr8E71E1fKw2ihYCTK8dQlVNo5QrXpg= = X-Received: by 2002:a05:690e:419b:b0:649:ec59:726c with SMTP id 956f58d0204a3-64c787d60fdmr4968031d50.21.1771786750412; Sun, 22 Feb 2026 10:59:10 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <3ACF2D3E-0376-4033-8CAA-84FAD83E2A69@gmail.com> In-Reply-To: Date: Mon, 23 Feb 2026 00:28:59 +0530 X-Gm-Features: AaiRm52r57WwvXiPoO_OefqyfMooJmONkHtcObUmPrY-0VYTD7Sx0isvzKJYmzM Message-ID: Subject: =?UTF-8?Q?Re=3A_=5BPHP=2DDEV=5D_=5BRFC=5D_array=5Fonly=28=29_and_array=5Fexcept=28=29_?= =?UTF-8?Q?=E2=80=93_Utility_functions_for_array_key_filtering?= To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: Claude Pache , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000e04bf3064b6e3f96" From: arshidkv12@gmail.com (Muhammed Arshid KV) --000000000000e04bf3064b6e3f96 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Here is a simple example of an `array_only()` implementation using existing PHP functions: ```php function array_only(array $input, array $keys): array { return array_intersect_key($input, array_flip($keys)); } ``` This works, but `array_flip($keys)` creates an extra temporary hash table. So peak memory becomes: input + keys + flipped array + result. In a native C implementation, we can iterate over `$keys` and copy values directly into the result without creating that temporary array. That means fewer allocations and lower peak memory usage, especially with large key sets or inside loops. Thanks. On Sun, 22 Feb 2026, 11:55=E2=80=AFpm Tim D=C3=BCsterhus, wrote: > Hi > > The same comments as with your other RFC apply here. > > On 2/20/26 18:37, Muhammed Arshid KV wrote: > > 1. Yes, *array_intersect_key() *and *array_diff_key() *can be used toda= y, > > but the RFC proposes dedicated functions for better readability, less > > boilerplate, and potentially better performance and lower memory usage = by > > avoiding temporary arrays. > > Can you elaborate on what you mean by =E2=80=9Clower memory usage by avoi= ding > temporary arrays=E2=80=9D? > > > 2. Good point about naming. Making the key-filtering behavior explicit > > (e.g., *array_only_keys* and *array_except_keys*) improves clarity and > > avoids confusion. > > I don't think that `array_(only|except)_keys()` is particularly clear. > From the naming I would expect it to return the array keys / values > (i.e. do the same as `array_keys()` and `array_values()` respectively). > > Best regards > Tim D=C3=BCsterhus > --000000000000e04bf3064b6e3f96 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

Here is = a simple example of an `array_only()` implementation using existing PHP fun= ctions:

```php
function array_only(array $input, array $keys): array {
=
=C2=A0 =C2=A0 return array_intersect_key($input, array_fl= ip($keys));
}
```

This works, but `array_flip($keys)`= creates an extra temporary hash table.
So peak memo= ry becomes: input + keys + flipped array + result.
<= br>
In a native C implementation, we can iterate ove= r `$keys` and copy values directly into the result without creating that te= mporary array. That means fewer allocations and lower peak memory usage, es= pecially with large key sets or inside loops.

Thanks.


On Sun, 22 Feb 2026, 11:55=E2=80=AFpm Tim D=C3=BCsterhus, <tim@bastelstu.be> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">Hi

The same comments as with your other RFC apply here.

On 2/20/26 18:37, Muhammed Arshid KV wrote:
> 1. Yes, *array_intersect_key() *and *array_diff_key() *can be used tod= ay,
> but the RFC proposes dedicated functions for better readability, less<= br> > boilerplate, and potentially better performance and lower memory usage= by
> avoiding temporary arrays.

Can you elaborate on what you mean by =E2=80=9Clower memory usage by avoidi= ng
temporary arrays=E2=80=9D?

> 2. Good point about naming. Making the key-filtering behavior explicit=
> (e.g., *array_only_keys* and *array_except_keys*) improves clarity and=
> avoids confusion.

I don't think that `array_(only|except)_keys()` is particularly clear. =
=C2=A0From the naming I would expect it to return the array keys / values <= br> (i.e. do the same as `array_keys()` and `array_values()` respectively).

Best regards
Tim D=C3=BCsterhus
--000000000000e04bf3064b6e3f96--