Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102455 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1220 invoked from network); 26 Jun 2018 14:42:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2018 14:42:10 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.208.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.208.48 mail-ed1-f48.google.com Received: from [209.85.208.48] ([209.85.208.48:33956] helo=mail-ed1-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/55-50433-0C0523B5 for ; Tue, 26 Jun 2018 10:42:08 -0400 Received: by mail-ed1-f48.google.com with SMTP id q24-v6so1163600edr.1 for ; Tue, 26 Jun 2018 07:42:08 -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=ITAmENSmJZgeeK8/qmY4Jlluc9PWsyQMP/VkHwZ4J9g=; b=H4dGOMoM8lTkm7ivd5Es+0T3uJ/rYNcEurpkZ/6g6opsdCnIN/SxguBBLa31//Ocsw W3SHwx/U0Wyjj1BslMHYwKVMFYX5WLBpLU6tpDRg9//uAn1+ZbgvS2E1mvLq2Zo6S9qD wTxopO04iaJQeYRXe38DesnkzB7pWD4+Bo+nmfCtFb4vgj8agUyANZMBJOmZqSypvVxA P4eTOPjCh5AVWBZbozPRjJl9uOol3VRPO1j4a+2eIFi9O1E0CPgLGdggyxunMJVoKvE8 YhkjrvYNwW9Kb4grwFPGj/T6qYe1I3CL0HQkH2uFVrK47EfCMcJrmSBOIX4UYD0jMT95 2/QQ== 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=ITAmENSmJZgeeK8/qmY4Jlluc9PWsyQMP/VkHwZ4J9g=; b=mAqqQj6a9l8AkswoW+JGG0FJYkLuCJzCW2wcubAxxenm5OyDf3PhwKp+hoOAy0Jv/H RHLMc8A4+xz2PrFJZwuYSeiz0bKDnmatreyBmI421E91MMr7y5UCVHmMGLgHamAIpdFj TLbVypiudmcO73YHmgbiR03ngvblsMpnAGZv42DfjvlOXVgzpappxOVkKKYuXL4x/ObQ egpUWPSL9yhQynhBd9gdNbarrhngGrA2qfnsxNGY3P4GjCRpikksNk4OrX+nmOid6Yu1 oSW8TUL44k8EStvKLLZx7GcNg08t6U13Qs7dJGTnC8FgJk2RgENaEeb2R2sdS8NP2vZl PCUw== X-Gm-Message-State: APt69E3HvpT6OtbG3+TUogjXKNjjUZtgohWL68Rc2Tc6nO1pXcimp/Xi +JMl3mCIbHLsyzyHjPcNQmeEM3PEIq+3Yy8ftCM= X-Google-Smtp-Source: AAOMgpdd5UVCTp7GD0vrR+OVmVkD1ZKBSElJwYW8/h8wtezsmfGp1+BB6smmiwZ6EaDAcYl9pjb2xknt2iTjWhgS9fY= X-Received: by 2002:a50:f4d8:: with SMTP id v24-v6mr2130704edm.162.1530024125021; Tue, 26 Jun 2018 07:42:05 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:8863:0:0:0:0:0 with HTTP; Tue, 26 Jun 2018 07:42:04 -0700 (PDT) In-Reply-To: References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <3242366.BL9MUqXe46@vulcan> <2241856.Iz1GuBRvza@vulcan> Date: Tue, 26 Jun 2018 15:42:04 +0100 Message-ID: To: Marc Bennewitz Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000784173056f8c809e" Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: rowan.collins@gmail.com (Rowan Collins) --000000000000784173056f8c809e Content-Type: text/plain; charset="UTF-8" On 26 June 2018 at 08:58, Marc Bennewitz wrote: > Hi all, > > I just want to add some information that I feel it's missing in that > discussion - I'm sorry if it was mentioned already. > > 1. It's already possible to extract the key and value of any index > position of an array using array_slice: https://3v4l.org/mib99 > > 2. "array_[key|value]_[first|last]($array)" is in my opinion not a good > option as it lacks the possibility to extract key/value from any position. > Something like "array_[key|value]_index($array, $index)" where $index > would be the index position or negative index position from right. > The big advantage of separate functions is that they make the intent clear; we could combine all four functions into one: array_index(int $position, bool $key), but "array_key_last($something)" is a lot clearer to read than "array_index($something, -1, true)". Are there actually use cases for getting "the 5th key from the end of the array", common enough to make "the last key in the array" harder to write? Regards, -- Rowan Collins [IMSoP] --000000000000784173056f8c809e--