Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89958 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87736 invoked from network); 1 Jan 2016 21:51:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jan 2016 21:51:42 -0000 Authentication-Results: pb1.pair.com header.from=jbafford@zort.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jbafford@zort.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zort.net designates 96.241.205.2 as permitted sender) X-PHP-List-Original-Sender: jbafford@zort.net X-Host-Fingerprint: 96.241.205.2 nova.zort.net Received: from [96.241.205.2] ([96.241.205.2:52079] helo=nova.zort.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/C2-06661-EE4F6865 for ; Fri, 01 Jan 2016 16:51:42 -0500 Received: from [10.0.1.2] (pulsar.zort.net [96.241.205.6]) (authenticated bits=0) by nova.zort.net (8.14.5/8.14.5) with ESMTP id u01Lpbiw028266 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 1 Jan 2016 16:51:38 -0500 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) In-Reply-To: Date: Fri, 1 Jan 2016 16:51:36 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <86A2B77B-3DCA-420A-A044-C68158E6C4C4@zort.net> References: <070A1824-9ED7-4863-92AB-A4366AB92C98@zort.net> To: bishop@php.net X-Mailer: Apple Mail (2.2104) Subject: Re: [PHP-DEV] [RFC] array_key_(first|last|index) functions proposal From: jbafford@zort.net (John Bafford) > On Jan 1, 2016, at 16:38, Bishop Bettini wrote: >=20 > On Fri, Jan 1, 2016 at 3:44 PM, John Bafford = wrote: > Happy New Year, everyone! >=20 > I=E2=80=99d like to present the first new PHP RFC for this year, a = proposal to add functions to easily get the first, last, or an arbitrary = key (and value) by index from an array, taking advantage of PHP=E2=80=99s = property that arrays are ordered maps. >=20 > Thanks for submitting this RFC! I am +1, with one quibble: obtaining = the value by reference seems non-sequitur to the function itself and PHP = in general. IOW, this seems more PHPesque to me: >=20 > // get the next to last value > $key =3D array_key_index($arr, -2); > $val =3D $arr[$key]; >=20 > Sincerely, > bishop While relatively rare for PHP, these aren't the only functions that have = an optional second return value by reference. (preg_match, preg_replace, = str_replace, among others.) I agree that that=E2=80=99s a bit unusual in terms of PHP, but, if you = actually need both the key and the value, this way you can do it in one = call, rather than having to access the array and pull the value out of = it separately. The C code already has a reference to the hashtable = bucket, so returning the value if it=E2=80=99s needed is trivial. -John