Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102323 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76080 invoked from network); 20 Jun 2018 14:09:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2018 14:09:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:35153] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/B4-32156-5106A2B5 for ; Wed, 20 Jun 2018 10:09:26 -0400 Received: by mail-wm0-f49.google.com with SMTP id j15-v6so7270819wme.0 for ; Wed, 20 Jun 2018 07:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=TK5hVncNKp29SJ6CQTTTjBu1Wc9eYlqHwq1hVej3m60=; b=PYL+qvckmnnKdrmUzOmbRzZjOq61on4CTNnduuN0T8/cEqzI0xGNGh+J6uGH2VOI/7 c/QKm2DEYD1N6yfuPWzw3l/XxjVNiK5SAcRSKTQ+1h0eb1FPWFotXpXcXAX7fBuikyza b59k/juMgqY/rTn7MYFXozzfc6jlb56PxgwwzbZpbmjrm0L28FvYXMPRQSDpxhDlCbTJ Y/f2mHBUdft9xB5z0mJmc/b36DdQB0BrBB5Q8/1tqJ5Iu7slmkKa7oNqcWVOUEKV0t8A LIgTsRwpN3tQj3C02CGUyOLSU4azy+yEhevVghIKKaYLU2FB3lAA0cywISI60Vxb2rHH SJrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TK5hVncNKp29SJ6CQTTTjBu1Wc9eYlqHwq1hVej3m60=; b=ASAgKzkK/tHxOr6p9+TeSCIIeUz134pHsdpbhKQXbbeNKgoxZwcrSxlFzaUUeIuAH+ gpRhuZ2bBU74u48uYaEca2/IHEcFL5uP2x8BN/KLrZgobRrAlsMR4CkQ8pIk1RiaqZXb ncSrdqtDSd8s/5FNAgCYI4REYtqp/jK9YVVHM5Pr/szDACjggqHoRAmQ8D2RAg7brcyh M04IdpB9SdOBh++ll7hLPisJMLYBIL1dVwzUhpsOhqe4JTI4CqiysGFL05Km9VZhQafy 10HjtBrF8g5e7tRwe03buEUk3xjmf2Ar/wOvL9+M3FrULRPvpEPh5RINieu2/8/Ak3gr C5Hg== X-Gm-Message-State: APt69E11V/VFPZLtpckJNf6tAzmYnyHMioZG70cy6T83KYaijdHLDIFj 54DXYPm5mcqFRhF4X+bEOJQ7/X6OkXtKZSJED6o= X-Google-Smtp-Source: ADUXVKJIRq51VQiSNpGbykwR8dcsePbHIE+zbJFoYeSNyVHwTKDi9y6OkZo3NJ74t/IhlilTZ2A+Ug3MQo424OdI6+I= X-Received: by 2002:a50:8143:: with SMTP id 61-v6mr18894665edc.100.1529503762125; Wed, 20 Jun 2018 07:09:22 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:8d55:0:0:0:0:0 with HTTP; Wed, 20 Jun 2018 07:09:21 -0700 (PDT) In-Reply-To: References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <76e4744f-6722-ee49-0325-e4433236f1b1@web.de> <73ac8914-8c9f-e74b-a4f5-f6e39cd96f8f@gmx.de> <3242366.BL9MUqXe46@vulcan> <154ba124-2915-ca36-fa39-5df6726d3b5a@web.de> Date: Wed, 20 Jun 2018 15:09:21 +0100 Message-ID: To: Levi Morrison Cc: enno.woortmann@web.de, internals Content-Type: multipart/alternative; boundary="0000000000006c96f4056f135824" Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: rowan.collins@gmail.com (Rowan Collins) --0000000000006c96f4056f135824 Content-Type: text/plain; charset="UTF-8" On 20 June 2018 at 14:55, Levi Morrison wrote: > > if ([$key, $value] = array_last($input) { > // do something > } > > Unfortunately, this won't work. I didn't know list() could even be used as an expression, but apparently if it is, it evaluates to the whole array on its right-hand side, which makes sense. So, if array_last([]) returns [null, null], then [$key, $value]=array_last([]) will also evaluate to [null, null]. Since that's not an empty array (it has two elements in it), it will evaluate to true. https://3v4l.org/lIEa1 If, on the other hand, array_last([]) returned something empty, like [], the list() assignment would throw Notices for the implicit access to elements [0] and [1] of the empty array. https://3v4l.org/qhq5R Regards, -- Rowan Collins [IMSoP] --0000000000006c96f4056f135824--