Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130210 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 242311A00BC for ; Sun, 1 Mar 2026 14:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1772374990; bh=UgSLalvCOK7Xzp152Qk9ARKVfqBcCsdsoqPFn4gu0m0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZQaP2BA/iv27kK54gkeCga/aoaJi1rvOkrSd4SEN7nFhtupfuKB1xpKANmIgLbbmb UGRCuGUAinUzjiZy55u1aOevyc4YU/ZSyRDeHbS7WhkunvOm1oMkuXu86zJdQH9Nmo UAQxJqjtgx1klQPM3XiVoJdUwddJ3jaNW6GsJmG7bIdeRi4lOEefLdsskQq/kmKeuc Y9frYC6vkJb/VzeUruIVISnzd/5sUfzzFtcijmSM5OxnMPZc3+R9YS17WA+PeVqJg7 bxUIfpU57W9C4+6lPGo03NQnoPRxCPF9wQRE9aP4Pt210JBktBYfG+CA7Z0lzJa0eD PgAkmsUqQEupA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 37C3E18006E for ; Sun, 1 Mar 2026 14:23: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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (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, 1 Mar 2026 14:23:05 +0000 (UTC) Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-64aea64bf15so3031576d50.2 for ; Sun, 01 Mar 2026 06:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772374980; cv=none; d=google.com; s=arc-20240605; b=Fat+qnaGvTbFsG1zw5KWBAhfHCfl0c2Jk38qt58BBx7SoGOZnfPnu1unpLmlsu1wq1 GNPrk9QFp0FxeiCh7AAV8fkP5S9MOws9XpJNtEfk2mFbMZjC5aQFgd8o5ee1KWtpgltc haBJAMuLivakhONbX5iZIzS8KPV0HPXzspXYIFp+487ouMcgx/KHTIGAC87GIq0OsWI8 wy8qmpbBRegWqKQEEPY/nH1BtXKxq5aVCgLz8coa59OKoI5nUYGEtSqq+g5xwxwXz/NF bMHRry6xhQ9014tyi3em0AIJGeNxDdxb3lUvvEcXKZTSOqdW6ze1RycIRAULoxShySST fnqg== 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=2dGdIbMmrHj0s97Mh5wPd6PMgtXfTb/e/ELKStRF6pU=; fh=atk/8FziTMkG2xxcWZt3tUVHbdILwslsY5hJ5TA7ALw=; b=Pa/BnPWPXLZ1kMHHBmePq1LiGYVtby3RA0rRbimM7xkAEQwrXyViLitrP+LjUdLnpc EzFDr4LbkvD1sEsE50beaYAmojnu3fp0lPJYWc4wRrUQLB8QZZ5VnYW6wOSuURdfaaMn Tjmw4LF243+GeFYPNknXzs46FXyV3+PoXHGOcNOwET5OGuuophM9DH9DMVWaORNzxvvZ xHqOE+jF6iwYES4ZSItmq7R4tWHXTyJHpL3FEB+ieNpDYERDHtGliRnzRYiNz28Rf3h0 eT8G1m9TL5OKco6XgapFnrk8jc68pAXF3kXqNCFQkZ0FmEdbACGk5sddAolTS64EYURv WTUw==; 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=1772374980; x=1772979780; 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=2dGdIbMmrHj0s97Mh5wPd6PMgtXfTb/e/ELKStRF6pU=; b=BE8fuU8nXuqq+dq2+GkzsEVZcuAswe4uB9e24y+/ZOD7o2YlEDdrVXzOvQRl0CTO6P 8Fg8rmTxY+CCvSejcvNyQRvm5vdNGc9h/VKgBubYq/92IBwEDNR+yawSeJXPbxrFf7el skCU8Theb6PSuIuZSihnuwtfJr/bWKj4RgbO2XUitMyTpR45LhOrh2KMgUA1pIoF2s29 7WtpTUtUyGqQqF+vSbMLixZpb1sHz2tZS85gHaM7eI6q1eHyXYZM+wrcPHaXK5NUV2Lp 5HEZ3R9l7yWWTCCD3ir2rh6+xH4zFpsnWmdswCE1h+E9AyMOhc+V2y1ASE4AgW1B4amn z96w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772374980; x=1772979780; 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=2dGdIbMmrHj0s97Mh5wPd6PMgtXfTb/e/ELKStRF6pU=; b=xVVkm3Hbv3U7PVjBYtTujTjv9KC3uqZdHrkt95lbrTdcVqlqnMX6/0f7MzKdBa8LtD ofQk39g5IrwXMwXzFjSASfOTlKZ7P8cjOSkg35c3LgVi9fux00aeLL8Ha3NF0aOLaWyP VFKIbkxg4pYP7WakSM4pO2xzwd3rIoW4shE2MUQ9sM/daCDFdAUu4O8cDZlfyGW9lxKV Els5MggzwbaScarvLl+KEiJVLF0k+15Vmu5HeYGaYcTiOkXEpWOyXQ3BfyIUtO+rm2B2 8XThXbQ0TucaXZPHeSEX+Kfzec+RijjwF3djOK93mIM1iH2W8Vgx6cMhlwOO7Z3uFUoU c/Hw== X-Forwarded-Encrypted: i=1; AJvYcCVjQoeYx6MyoKeq46iiOBJXHfkvBl4IdRbOcFTSB+AMCJd41Y6lBWtXXF6jkKB9ScrTbYKh0buofm0=@lists.php.net X-Gm-Message-State: AOJu0Yw/ZJeatKVJklJYSSdz+ulsm4ywqKOgYs2Ly5LOka3eb9+hnvl7 Ozuf2IB1YJBnVajExoGfef2KwM1QJeuKOAfPQ6CXoJNM0dvl+HiQ8gxSsTWXqLyeRK7n1n7ziHX n0v9irBvF7X1O0FjGd4+vqdQXpQ0grok= X-Gm-Gg: ATEYQzz89QhiIh3YwpDWX7Pbiy11O+3d6G4d9nRIkCEafL6H5SOuMTskQ8WCLoexMSW bZ16qITrChBhfgxTqhdDzYSkKXuINYD32GX+RrtvtofhNVTuUykjYWSvqEveAEEk4gJ7wwBYrdA hd5wnnXQ9SbqAudRBbrhyJnpovRD0A0CYsZCEJUojY3smWT/xYggiTaOLSu8vi8D8kh2t5rEz4F eNFJWXCRz92GU1b74BYOSPSpuTiawYw1+o+FG4z1agQB+36SzEs1OAbQm0j9DA0dw6R8lOR2VNF /4dQlPJAzgK3Lc5xX14kVMwOpsjY2kYiOYn4Z1sA8MxNRDdnzuBa8qa1d7GJoEDXJzmIl0gu X-Received: by 2002:a05:690e:d53:b0:641:f5bc:6934 with SMTP id 956f58d0204a3-64cc237cd67mr7503720d50.72.1772374979913; Sun, 01 Mar 2026 06:22:59 -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> <359310a0d41524f9d7187e75379b16a9@bastelstu.be> In-Reply-To: <359310a0d41524f9d7187e75379b16a9@bastelstu.be> Date: Sun, 1 Mar 2026 19:52:46 +0530 X-Gm-Features: AaiRm52wdfYrzMI7lmkV6FxuJxAIgyyb4-rQ6JW9Lml61K4PKIDB2IrIFqx2CVM 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="000000000000162bc0064bf735e3" From: arshidkv12@gmail.com (Muhammed Arshid KV) --000000000000162bc0064bf735e3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Tim, Thanks for the explanation. In this example, $dataWithOnlyIdAndEmail =3D \array_intersect_key($data, ['id' =3D> 0, 'emai= l' =3D> 1]); the second argument is an associative array. But in my *array_only(array $input, array $keys) *function, *$keys* is a *numeric array.* Working with a *numeric array* may be slightly faster than building an associative array first. Just wanted to clarify that point. Best regards, Muhammed Arshid KV On Sun, 1 Mar 2026, 7:40=E2=80=AFpm Tim D=C3=BCsterhus, = wrote: > Hi > > Am 2026-02-22 19:58, schrieb Muhammed Arshid KV: > > 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. > > That is true for this specific implementation of a =E2=80=9Cwrapper funct= ion=E2=80=9D. > It is not necessarily true for other implementations, e.g. simply using > the functions directly instead of creating a wrapper for two method > calls. `array_flip()` supports compile-time evaluation, so you can just > write: > > $dataWithOnlyIdAndEmail =3D \array_intersect_key($data, > \array_flip(['id', 'email'])); > > and OPcache will make sure to rewrite it to: > > $dataWithOnlyIdAndEmail =3D \array_intersect_key($data, ['id' =3D> 0= , > 'email' =3D> 1]); > > avoiding the intermediate array. > > Best regards > Tim D=C3=BCsterhus > > PS: It appears that the RFC is not listed in the overview at > https://wiki.php.net/rfc. > --000000000000162bc0064bf735e3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Tim,

Thanks for the explanation.

In this example,

$dataWithOnlyIdAndEmail =3D \array_intersect_key(= $data, ['id' =3D> 0, 'email' =3D> 1]);


=

the second argument is an associative array.

But in my array_on= ly(array $input, array $keys) function, $keys is a numeric ar= ray. Working with a numeric array may be slightly faster than bu= ilding an associative array first.


Just wanted to clarify = that point.


Best regards,

Muhammed Arshid KV


On Sun, 1 Mar 2026, 7:40=E2=80=AFpm Tim D=C3=BCsterhus, &= lt;tim@bastelstu.be> wrote:
<= /div>
Hi

Am 2026-02-22 19:58, schrieb Muhammed Arshid KV:
> Here is a simple example of an `array_only()` implementation using > existing
> PHP functions:
>
> ```php
> function array_only(array $input, array $keys): array {
>=C2=A0 =C2=A0 =C2=A0return 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.

That is true for this specific implementation of a =E2=80=9Cwrapper functio= n=E2=80=9D.
It is not necessarily true for other implementations, e.g. simply using the functions directly instead of creating a wrapper for two method
calls. `array_flip()` supports compile-time evaluation, so you can just write:

=C2=A0 =C2=A0 =C2=A0$dataWithOnlyIdAndEmail =3D \array_intersect_key($data,=
\array_flip(['id', 'email']));

and OPcache will make sure to rewrite it to:

=C2=A0 =C2=A0 =C2=A0$dataWithOnlyIdAndEmail =3D \array_intersect_key($data,= ['id' =3D> 0,
'email' =3D> 1]);

avoiding the intermediate array.

Best regards
Tim D=C3=BCsterhus

PS: It appears that the RFC is not listed in the overview at
https://wiki.php.net/rfc.
--000000000000162bc0064bf735e3--