Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102449 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76637 invoked from network); 26 Jun 2018 07:58:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2018 07:58:47 -0000 Authentication-Results: pb1.pair.com header.from=dev@mabe.berlin; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dev@mabe.berlin; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: dev@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:40344] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/82-50433-132F13B5 for ; Tue, 26 Jun 2018 03:58:45 -0400 Received: from [2a02:8109:9d40:1d44:5545:67e2:9e5a:3243]; authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1fXis2-0005Rq-K3; Tue, 26 Jun 2018 09:58:38 +0200 To: internals@lists.php.net References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <3242366.BL9MUqXe46@vulcan> <2241856.Iz1GuBRvza@vulcan> Message-ID: Date: Tue, 26 Jun 2018 09:58:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <2241856.Iz1GuBRvza@vulcan> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;dev@mabe.berlin;1529999925;473f0834; X-HE-SMSGID: 1fXis2-0005Rq-K3 Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: dev@mabe.berlin (Marc Bennewitz) 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. Thanks, Marc Am 21.06.2018 um 18:16 schrieb Larry Garfield: > On Tuesday, June 19, 2018 9:47:01 PM CDT Levi Morrison wrote: >> I don't think I'm getting all the mail I am supposed to. I hope this gets >> seen. >> >> I propose 2 functions *only* which I believe covers the use-cases that >> all 4 of these do and more, with shorter names, and the ability to >> discern whether the call succeeded or not. >> >> list($key, $value) = array_first($input); >> // $key will be null if the call failed >> >> list($key, $value) = array_last($input); >> // $key will be null if the call failed >> >> I have tested it with user-land functions and seems to work as >> intended in all success and failure conditions. Verification that it >> works as intended with internal functions is necessary but this seems >> a much better proposal to me. > > Can I vote "heck no" to any function that does multi-return, thus making it > impossible to chain or pass directly to another function? That's an idiom > that just doesn't make sense in PHP. > > --Larry Garfield >