Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123162 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 qa.php.net (Postfix) with ESMTPS id 7D3361A009C for ; Fri, 19 Apr 2024 20:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713557377; bh=c5m9YVXggKsTL/Z8OrZKWx5Ut7ziwbGJ38pGW+bDuGU=; h=In-Reply-To:References:Date:From:To:Subject:From; b=QR702TJGPsoMrLCke8iz6mG0ql3hynrE6k+HTwSDSN/PFtLg6mOyP+DsLDqRcNx4Y ZhCATdbqjX4lb1KbbCWF3TVfgGRQODnFrDLldEsF5pW5gmMCk3xz/xSlL4D+l3u5mV 6OECj1nyIn/0wJuQXbgyMY1NMoTdF2VCXY8azbxSPSfevmFPujSbZSmEZfD3i7JqVA z1FYg51sMVtPD3vittWA2C9394oM7C544jMrJlXeYzXPHQ6SJywd1T7grkDnUnUU3C FVh8iVFLv1L4BjvQEoenL/sHakV00aa7yhPIUDsi/A3btUGWVDhRzKSFxV5ls5MKod 6a6mQJ5F0Ha/w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DBE971809BD for ; Fri, 19 Apr 2024 20:09:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (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 ; Fri, 19 Apr 2024 20:09:35 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 7F9C818000D5 for ; Fri, 19 Apr 2024 16:08:55 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 19 Apr 2024 16:08:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm3; t=1713557335; x=1713643735; bh=e0MWLvFn8DaawxdrXyAkk 6OfqMnRUXQ7WcYDOTudl20=; b=22oLDIG6DC8mcxhs5rfH8LpUvMjW7YgvUF7qU qgxPUASUgYuddt7tbUuE644Jyucnk4CBuvcihRa0wHkHwjBTsiM8nLt10WDrWXMe 37tf6DritzgNMBStiAC5SwtkIEp0pKMIwBa72V3dHVQi+SYOAcnWqkNTyfNO8tCI 7IzU77Sd+qolYWd8nEpavSdwtOSVliTjEx78JYzvGhgDu6ElBzgwYbPBjlUUUIfi kDM+v488WivCzZuwFd9cqnu8ai/4W/o3COpeAD6yhNdejjTwTlC8iMF02Ihh+Dfe O/3Eyv1vMbNLabd3z07qGnyttw3KBFbQzw1aFWjN1Gn1PmNyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1713557335; x= 1713643735; bh=e0MWLvFn8DaawxdrXyAkk6OfqMnRUXQ7WcYDOTudl20=; b=L j6koKjYJ3r0asjFK+5O7DAuDllQISXMGcmci3Tsn0e3Bs5x2pbaGE2V+EZkCk/x3 Lo4/XLX9ax5N/yYqhvdQM7hz3lLDSBYF89XW4w7Wyn24YidpKEf+3TEKK4CDpTi+ 0PMeidx/5xud4bcqL/kystG/5KllHAUYrKKadrTLZGgCQlaNe3shM3fRDXk3QoPT tPfF8rtzqqFS5CxyiYsdjXRXSXkpf9pag4XUeMowjt2Tx7ClMyLS7rCZUnUBdAdj o6FmDVYjaFDSWgpkciu4KjEGeg+PW2zoZ6MmwaQ92toX4ETpUZ7WAkVU5ySJFm6F V7vfXNKPL5dOa88znfIrQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgudegkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 886B41700093; Fri, 19 Apr 2024 16:08:54 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-379-gabd37849b7-fm-20240408.001-gabd37849 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <4bdc94d9-f35b-423a-b3a7-1a91fbf48424@app.fastmail.com> In-Reply-To: References: <24e4529d-0b75-44de-90ef-34de5dfb1c99@wcflabs.de> <278889be-82ab-4827-a9e7-801b5ba2d8f8@app.fastmail.com> <45b726f4-8085-43e2-b701-6b35bc249409@wcflabs.de> <2dd7ef64-d1c5-4ed8-964f-b86dba110e0d@app.fastmail.com> Date: Fri, 19 Apr 2024 20:08:34 +0000 To: "php internals" Subject: Re: [PHP-DEV] RFC [Discussion]: array_find Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Fri, Apr 19, 2024, at 7:34 PM, Joshua R=C3=BCsweg wrote: > Hi > > On 10.04.24 00:12, Larry Garfield wrote: >> Another alternative is to always return the key, because you can triv= ially get the value from the key, but not vice versa. Of course, the re= sulting syntax for that is frequently fugly. >>=20 >> $val =3D $array[array_find($db, $array)] ?? some-default; > > > In 95% (roughly) of cases, I (personally) need the array value and not=20 > the key. Just having the option to get the key is already a step forwa= rd=20 > compared to the current state, but I personally would find it=20 > impractical (and fugly, as you said) to use the method, especially if=20 > the search callback is more complex and multi-line (and it is fugly, a= s=20 > you said). > > Here is an example for this, without using a helper variable: > > $value =3D $array[\array_find($array, function ($value, $key): bool { > if ($key % 5) { > return \strlen($value) < 100; > } > > if ($key % 2) { > return \strlen($value) < 40; > } > > return false; > })]; > > So I think, this is not an option. > > Cheers > > Josh I think at this point I'm on team "let's just make it 2 separate functio= ns, give them good names, and move on with life." There's another issue, though: Will the callback always be given both $v= alue and $key? If so, it's incompatible with internal single-parameter = functions. If not, and it tries to auto-detect, we run into issues with= functions with optional second arguments. (This is a pre-existing mess= I've run into before.) --Larry Garfield