Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120507 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87427 invoked from network); 2 Jun 2023 00:15:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jun 2023 00:15:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A2190180503 for ; Thu, 1 Jun 2023 17:15:41 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NEUTRAL, T_KAM_HTML_FONT_INVALID,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 1 Jun 2023 17:15:41 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B922B5C0163 for ; Thu, 1 Jun 2023 20:15:40 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute2.internal (MEProxy); Thu, 01 Jun 2023 20:15:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1685664940; x=1685751340; bh=K4CWyWOi3QkmJ sMuFz6f3oe59fY/0ae4v+71IwO+pQ4=; b=Rl5fPngMYp9agLteHliKWYtXntRIZ nQw8XVDbPO0NBt9WSEm1TTea6lNlNv+5lGx0sWU4kOoBBtJlsjrw/Wj4KG0DiV6J yHMFhzvaHlZWm1glt+CuONik1pnP/m8+slJ+HhsVaFowEs9taa0Brak2OGRPAWwA wy6rklro7reoMapSrkjCubGdNiFfPtrzs7DFNdoqI7IKqP4X2sA6BRBUlIHdM5X2 XfVtgFVSiF//MuCDql6IBsY1Qd0TBWZSOl1oUklvwgN3GMlv1atdKZGpZcU2ZJcb cfZeAIF4uUOwoFKsyQd60yIwToBshdF48tH2MhlAp3XD0obK6e7R/rK+A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeelvddgfedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerredtnecuhfhrohhmpedfvegrshhpvghrucfnrghnghgvmhgvihhjvghrfdcuoehl rghnghgvmhgvihhjvghrsehphhhprdhnvghtqeenucggtffrrghtthgvrhhnpefglefhtd eukedtteefuedvtedvkedtveefveelveeihefgvdfhheetvdffieethfenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghnghgvmhgvihhjvg hrsehphhhprdhnvght X-ME-Proxy: Feedback-ID: id4f946ef:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7435F1700089; Thu, 1 Jun 2023 20:15:40 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-447-ge2460e13b3-fm-20230525.001-ge2460e13 Mime-Version: 1.0 Message-ID: <6c66ad82-7616-4b22-8961-494b557a3def@app.fastmail.com> In-Reply-To: <97308c1d-e9f0-e28d-78ba-11da2a136ee6@fide.pl> References: <97308c1d-e9f0-e28d-78ba-11da2a136ee6@fide.pl> Date: Fri, 02 Jun 2023 02:14:34 +0200 To: internals@lists.php.net Content-Type: multipart/alternative; boundary=a9d00efa65a2435fa8e059bb4088377e Subject: Re: [PHP-DEV] Proposal: addition of array_find() and array_find_key() functions From: langemeijer@php.net ("Casper Langemeijer") --a9d00efa65a2435fa8e059bb4088377e Content-Type: text/plain On Thu, Jun 1, 2023, at 18:02, Janusz Szczypka wrote: > array_find(): This function would allow developers to find the first element in > an array that satisfies a specific condition. The condition would be defined by a callback function. This would actually be an alternative to a simple foreach() with an if() and a break. As your example implementation makes clear. array_find() and array_find_key() would still do the same internally, but add a function call adding the overhead of pushing parameters to stack, switching the scope, passing return value back switch scope and pop from the callstack again. If parameters or return value are typed this adds even more overhead. I don't think there is any optimisation possible when this is done in C. To the proposer it probably feels that this is an array function currently missing, but instead it's probably better not to have array_find() because people might actually use it for larger datasets. Although I acknowledge that it will reduce the number of lines of PHP code it doesn't actually reduce the mental capacity to read and maintain code. I find the simple elemental building blocks of loops, conditionals and expressions easier and more expressive. In my experience this is especially so for less experienced developers. Then there is a problem of naming. array_search() and array_find(). To a new developer, how would they know which is which? Also there is the missing array_find_value_and_key() method. Because why should we be limited to either matching the key OR the value? Greetings, Casper --a9d00efa65a2435fa8e059bb4088377e--