Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130209 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 635EF1A00BC for ; Sun, 1 Mar 2026 14:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1772374244; bh=OcfUR8+cBnlP5TYa/x1+rSGhYm860/YDlBnxYWInPFQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cfibE6wyBAsNMOhWsaa14gDmRO1gNYpXZoqFvd8cvK1gsxHSFQ+uPpAauwEXXGRfO iRKPuFaaKVnd+Ck6Zx20HoNMAToRaUuNYyql0O+Ehz6xRweW4nDT7eiJ/aDrCxjLTd 9hO8sGGLR/iYbxRuqzHCfwiaOFC+Esd5Ytkyvo2Hb0RgCeBKjuw0w/NiZhJBgsWUo6 gMJdvgj05ySuBhOQCd8Jqafim3dp8dQR7M0wU1FxB7STGOUbx2aW60GkNsER+1bu9J m1exA7RLcuoVBCN28SPHgPUvNFyV0+ccu22L9FW0Aq8cY/h8acftfCGqg2iGINAS5X 3VyLUvgDNipYw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A862A180078 for ; Sun, 1 Mar 2026 14:10:43 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1772374236; bh=krYXCiITkxuiXNvDdRErXxMt6nI4CZY2BtyFCcC3Ras=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=NDqbrRkz1Zff/Vm2/+WvaHzvVpb0Xfs/vrEq1TcnsCVqth+rrURqAhYHLzYwBGneu QSgrrv1WqsbpjoMaS7hNmuVLabNEFTCIRwf54RgYDtoVNX4IdbkTNxBQ7ZkUIFc9uX hxgTXed6oODH//F3AYK4fkkVMGYKCExZeOHtFtl6XllKI9wkC1+Gl5NSiV3PpccghA ktSkBDSh3nahEW/NwKLXUMsgY/agPQ5pqZGCQYXUW/zflIPoc8hRA/+XaFx+RV7lxI cSeL/GlB1YnVuj73GrBkl2JVM4CD8ejfOL6nvViOQ061GeCDedw/LpvRncyAm2og0A DAwJbcHVQDDFA== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Sun, 01 Mar 2026 15:10:36 +0100 To: Muhammed Arshid KV Cc: Claude Pache , internals@lists.php.net Subject: =?UTF-8?Q?Re=3A_=5BPHP-DEV=5D_=5BRFC=5D_array=5Fonly=28=29_and_a?= =?UTF-8?Q?rray=5Fexcept=28=29_=E2=80=93_Utility_functions_for_array_key_f?= =?UTF-8?Q?iltering?= In-Reply-To: References: <3ACF2D3E-0376-4033-8CAA-84FAD83E2A69@gmail.com> Message-ID: <359310a0d41524f9d7187e75379b16a9@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) 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 “wrapper function”. 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 = \array_intersect_key($data, \array_flip(['id', 'email'])); and OPcache will make sure to rewrite it to: $dataWithOnlyIdAndEmail = \array_intersect_key($data, ['id' => 0, 'email' => 1]); avoiding the intermediate array. Best regards Tim Düsterhus PS: It appears that the RFC is not listed in the overview at https://wiki.php.net/rfc.