Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121368 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92298 invoked from network); 18 Oct 2023 03:26:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 03:26:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2938F1804C1 for ; Tue, 17 Oct 2023 20:26:24 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-vs1-f45.google.com (mail-vs1-f45.google.com [209.85.217.45]) (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 ; Tue, 17 Oct 2023 20:26:23 -0700 (PDT) Received: by mail-vs1-f45.google.com with SMTP id ada2fe7eead31-457eb60c357so269630137.0 for ; Tue, 17 Oct 2023 20:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697599583; x=1698204383; 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=+VtT0Z7m93Ytydl9mbRQLtp8P0vGYEbJsV0mgYbAsFU=; b=RpYbdH3xwTR1cRitG88Tw876L5TmaU5QVEEWExt5TLmt9PcVsMTWtnHED+9D/D4t4M fMyEHxFzSeTQqQl/OG0IA9V0++/wtrYCrIqzI49Ixbbid8jEN+ePaabsp44xKNV/WGvN hVVExYHw5Ig4GURJ+uP99HpJCJqXQbD/1CpsUvkebQ4MuyR8P4WvFvQsnuTvOcJ8py1B Tul1OLHg2++YrGvQ4rm3hDmDcncd7RsNEJ0nED/vxIzeZPXmVQuSH82ZcBj2eFPOxHKj jG9UeF2xHU9VRvOgFuQgmGlFbxuySf+zq9jgKSTrEKSHr16YI6PtXMfCY+bIkFYjl/UT +sHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697599583; x=1698204383; 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=+VtT0Z7m93Ytydl9mbRQLtp8P0vGYEbJsV0mgYbAsFU=; b=lGl0U5x2KPpLYfYgo1SiBva551OTVFTDczw8ENkCzGhJUg61ByqZmPhkWKX8ceqwwM YtUTYHKYZuLaeiMkgypnR9EbdRqUCnIKU+dBTtl0xFuwkb/KiHTEoNgeiwlezxXM4e8N pTMRHu3vxF+gkgknLpCh3dWYOVCdVVB8/Se0zcUEnwOJzJZQtcIuFVHK5K3rH5714Mv+ wUJEuDb853h4PcHEKzIfUw65/RPEI9ue69goZ9ZHw6dvdumMVMSKOwcA3bORWhp5lpRP S/wHH+tgwoD0GtKXuXhJLkj8JyyLcGpV5j0tf4E2a0l7uiIe0oDV6ujh/bDagtkrM/0/ /Aog== X-Gm-Message-State: AOJu0YyyTLJ2rTeGtDn3tJ0R7d737cBBNvmRkgDbdAGxenptAEDZp4+K 2fw6XfsD0q0GgLaj3eyCeUBKVNrinK+/31WNjKg= X-Google-Smtp-Source: AGHT+IFztxkTrsq4Z1BTLJzvzA9QJ6/xKXhvHLitnBKFDyebbqUh6lQ4Owijio+JeBT/hY/WsSov9f51PRJre4ltikU= X-Received: by 2002:a1f:2394:0:b0:48d:8ba:b5d0 with SMTP id j142-20020a1f2394000000b0048d08bab5d0mr3138911vkj.0.1697599582736; Tue, 17 Oct 2023 20:26:22 -0700 (PDT) MIME-Version: 1.0 References: <173ca550-71a0-4bd4-96f2-b64b6155115a@app.fastmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 00:25:46 -0300 Message-ID: To: Brandon Jackson Cc: Saki Takamachi , Levi Morrison via internals Content-Type: multipart/alternative; boundary="00000000000019a08c0607f534eb" Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: deleugyn@gmail.com (Deleu) --00000000000019a08c0607f534eb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Oct 17, 2023 at 3:43=E2=80=AFPM Brandon Jackson wrote: > > There is also a technique to make the return value `[$key =3D> $value]` > instead of just a value, but this loses simplicity. > > Hmm, since the naming array_first and array_last doesn't clarify that > it's returning a key or a value. What if it returned both as ?[key, > value]. > > That opens quite a few use possibilities: > $first =3D array_first($array); > $value =3D $first[1] ?? throw new Exception(); > > [,$value] =3D array_first($array) ?? [null, null]; > [,$value] =3D array_first($array) ?? throw new Exception(); > This function signature can be accomplished by userland once we have `array_key_first()` and `array_first()`. It's much better to keep `array_first()` as simple as possible and let everyone build their own approach to go about it since we have so many approaches. --=20 Marco Deleu --00000000000019a08c0607f534eb--