Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121398 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79214 invoked from network); 18 Oct 2023 15:28:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 15:28:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9063B1804BC for ; Wed, 18 Oct 2023 08:28:56 -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-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 ; Wed, 18 Oct 2023 08:28:56 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2c518a1d83fso62820931fa.3 for ; Wed, 18 Oct 2023 08:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697642934; x=1698247734; 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=pLStWi1xPAhPUE7xBGlNPRBBPo+/TEpAG2VXc8ywOfY=; b=Iorrjre8Enu9AvCR1Ymu5R/U/6k0udWrHFoYTZHiJgWEDTp9eyJh621LVNjS5ZIL2C v3m1Zebz/gFMr8ZFGVEY97DGzvnkwL/OrXhB7qonSlCD1fqNBBl7k2n6fMW3DnQE5teP /DNSwkFuQpMqCFQeQmIVR1YzTyjfZTkCDJeibsrfnzSWnZYVh6QfVj/RsPXsuUMuoJhU g2esA4A9qFRDU2kdQ3Pi3Q7WCdEjKUzJ+Yp1lURJ8Pc5gyWCJpaHLaIxz5lwQwkb3wwM M1puTrzCZ6Vky4zw1xSXfHddKX5XL/S+CAgVlerL6yi8hb9SHlQSgRzAaz7o20s8f2lH B3Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697642934; x=1698247734; 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=pLStWi1xPAhPUE7xBGlNPRBBPo+/TEpAG2VXc8ywOfY=; b=KoIGvqBEA8z/0R66h5H5NMn1+yEGYzhrahyzYGB7ZBInF0EWe7xvsuUSXldXV0U7sv NQw6g2e5aXmrK81H0MdOPgfcyjD5YVJhONOgPLDq9a5mfSQg/EAkFjb9B5cO5mdjkfn3 EVQGArcVBEF83bWXeg/GC8YzFRIh0hYWns5nSr9CNBd7LMPQaA1IqtQ4v5vlVmuH8rJJ lgWCs0Dvoo2StupszzIOK4Yu9um+kCGADKVthzCqIElcKamA8JuVQ+lW4iHVP/TnsP/N ttEa75DaQxjQOu3Xev3AnMyz8rIlyS+/DlFVDYeKPQCwSKzQa6O91FKFQ9Fa0A5ADH71 ULsQ== X-Gm-Message-State: AOJu0Yz29tDwXBNFXmCVApuPVN1j1yGox2cc8Ai2en5dlS0Gh1TKn1Qx EJv41reXHNlq00wKVnO4F5CwOBV3QvJEoamW5F4= X-Google-Smtp-Source: AGHT+IFeqPZLzpV5UB7j3O5Rjboe/QO/KqSvNMX79vPoacsnYmAgzmpq252FAJwntVqDf7DM5owx9Tb2NroWj7xjMCA= X-Received: by 2002:a2e:b88c:0:b0:2c5:247d:581 with SMTP id r12-20020a2eb88c000000b002c5247d0581mr4779436ljp.22.1697642933717; Wed, 18 Oct 2023 08:28:53 -0700 (PDT) MIME-Version: 1.0 References: <173ca550-71a0-4bd4-96f2-b64b6155115a@app.fastmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 17:28:42 +0200 Message-ID: To: Robert Landers Cc: Deleu , Brandon Jackson , Saki Takamachi , Levi Morrison via internals Content-Type: multipart/alternative; boundary="000000000000050cf60607ff4c10" Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000050cf60607ff4c10 Content-Type: text/plain; charset="UTF-8" On Wed, 18 Oct 2023 at 17:05, Robert Landers wrote: > > This is simply not true, 0 is not always the first key in a list, > especially after filtering it. Hence there is a need for this function > in the first place. Just to clarify this point: If 0 is not the first key, then it's not a list. After filtering a list, you get an array that may or may not be a list: https://3v4l.org/VegUr Regardless, to add my 2 cents, I'd keep things simple and vote for this signature: array_first(array $array): mixed array_last(array $array): mixed returning the first/last element, or `null` if the array is empty. Or, alternatively: array_first(array $array, mixed $default = null): mixed array_last(array $array, mixed $default = null): mixed returning `$default` if the array is empty. Both look fine to me. - Benjamin --000000000000050cf60607ff4c10--