Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61228 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74115 invoked from network); 14 Jul 2012 17:05:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2012 17:05:58 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:58148] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/EC-20866-3F6A1005 for ; Sat, 14 Jul 2012 13:05:56 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 7F98B70003DC; Sat, 14 Jul 2012 18:05:51 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id bVqoDhgl5wUi; Sat, 14 Jul 2012 18:05:51 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id C7FD470003DA; Sat, 14 Jul 2012 18:05:50 +0100 (WEST) Received: from damnation (unknown [IPv6:2001:470:94a2:4:2123:f30f:bbf8:6cd0]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id D25F4200147F; Sat, 14 Jul 2012 18:05:48 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Stas Malyshev" , "Anthony Ferrara" Cc: "Brandon Wamboldt" , "Andrew Faulds" , internals References: <5000BF44.3080907@sugarcrm.com> Date: Sat, 14 Jul 2012 19:05:43 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.50 (Linux) Subject: Re: [PHP-DEV] Re: array_last_key() function From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Sat, 14 Jul 2012 04:04:27 +0200, Anthony Ferrara escreveu: >> I like this idea. array_first_key would be nice too >> >> I am probably missing something, but what those would allow to do that >> rewind/end+key() doesn't do? >> > > The big thing that it does that end()+key() doesn't do is really what it > doesn't do (update the internal pointer). > > end() modifies the array pointer. So if you try this in user-land: > > function array_last_key(array $array) { > end($array); > return key($array); > } > > It will always force a full copy of the array (at least the hash table). > Implementing this as a core function however would eliminate that one > side-effect... Why is the last key special? Why not a function to get the first or the penultimate key? Of course, there is one aspect where the first and last keys are special -- if you have some algorithm where you pop or shift the array successively. But in that case the argument about end() + key() having side effects is irrelevant because you are changing the array anyway. -- Gustavo Lopes