Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121322 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59015 invoked from network); 15 Oct 2023 12:00:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Oct 2023 12:00:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A304E180507 for ; Sun, 15 Oct 2023 05:00:09 -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.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 15 Oct 2023 05:00:09 -0700 (PDT) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-9b96c3b4be4so546911966b.1 for ; Sun, 15 Oct 2023 05:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697371207; x=1697976007; 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=dsmqDeksOekPqmyxbPpJ5WMKoX3v+Mo9Ej6wuat2MdQ=; b=go0d5PdriqL3UFPrKU633hIpdNpDDb568g8a8y6Ed0Aux1HP/J5ZCH2TJDZiX0LNRn uYrWYPfQzeKDlbDtEqiiRVh5IS29deE+McrMPWmGDTWS+fdbMk1O9mZLUTXnjynPgwwN OlC0EmQDvkg+bthl2GJgsft62DK/46mhcU1UXtGEe6FK3NcWhUVXzTdE+6AALh1Jhfsn 99H4H8xZuUAjM7Jw8sTlzSBCjmEKX76/26bI97hj13G09JVRB9GwNcQmFj86PIoO987X /LtWTIi66fqjCqSytWMf4WU3biZ4uFcwL/rlL+4C6tkN7e+n/ZlHSCWICdZdGjDTDSuG W03w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697371207; x=1697976007; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dsmqDeksOekPqmyxbPpJ5WMKoX3v+Mo9Ej6wuat2MdQ=; b=eF9SWvJ4lwVhhiSGu1YkKuFZr1c76zYyIhRh4w9fhmIEp8qlEQUG3hYy4Jkh3RpODf NnhEn5I3O1YBDGX3cVRNJtxxCD69vzUtUrZIXrnt2+Mg5NZBMihfCo940PpZGk8nH6j4 ss2sUouUhdrSxFNnicnBTdCAHh8nzN3P8ticVSEYNuqfMA0dbnjFUh1crMp5VQ8241xx +K25fI0WCM2pq8/unTrMvYlm16qK6EmwKLNnYetasFUw47CSPFQYMrx0XIAupmuSx3vq YiU45W0lOKGZJc5aX1L9S1jOAinDdAVdb4iXAkOTdmH6LvpqSEOPsnEvHpF8e3yE0Bfi aQkg== X-Gm-Message-State: AOJu0YyNvs/TtbmE0+qnrWHfF8hMBednrrZllCRFZNtVjXvbJyTHn0MF G2dDAh8RcN2yhDr3QR1BqpMMdOjoqCLaACZTDLg= X-Google-Smtp-Source: AGHT+IESQrc6WpJ4xNlOP5l+r+r0D3Q9aXdk/oMcDWHd+up04Ov0nCduTlnRVklLWKwA3jcdwqT5Oq0AjOPD+NJUJsk= X-Received: by 2002:a17:906:8a49:b0:9ae:5202:e611 with SMTP id gx9-20020a1709068a4900b009ae5202e611mr26217369ejc.14.1697371207380; Sun, 15 Oct 2023 05:00:07 -0700 (PDT) MIME-Version: 1.0 References: <3006DBD0-411C-4855-A101-9B8861544B61@sakiot.com> In-Reply-To: Date: Sun, 15 Oct 2023 12:59:51 +0100 Message-ID: To: Saki Takamachi Cc: David Grudl , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000de32260607c0075c" Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: dragoonis@gmail.com (Paul Dragoonis) --000000000000de32260607c0075c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 15 Oct 2023, 04:49 Saki Takamachi, wrote: > I came up with the idea of =E2=80=8B=E2=80=8Busing a signature like array= _filter(), and > when a callback is passed, "return the first/last element that matches th= e > condition" and "return null if there is no match." > > The downside to this idea is the loss of simplicity. So I'll leave it up > to you whether you want to go with this idea or not. I have no intention = of > forcing this. > > Best regards. > I'm in favor of these functions. Right now I am doing: $firstItem =3D current($array) $secondItem =3D next($array) Which is simple and works, but really it's just by design that the code hasn't shifted the array pointer yet and I can cheat with current() If the pointer was shifted then I'd have to do reset(), which isn't good. array_first() for the win Many thanks, Paul > Saki > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000de32260607c0075c--