Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61226 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68113 invoked from network); 14 Jul 2012 15:28:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2012 15:28:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=john.lesueur@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=john.lesueur@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.182 as permitted sender) X-PHP-List-Original-Sender: john.lesueur@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:43927] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/FB-20866-B2091005 for ; Sat, 14 Jul 2012 11:28:43 -0400 Received: by wibhq12 with SMTP id hq12so1246409wib.11 for ; Sat, 14 Jul 2012 08:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=EuQ9gKp2wn+titxgYC+1U32pD0/aWBT+veYrtReUXVA=; b=tu0vehHAv9bZcMv8bz/OxkMH4kNzxcHk4AUOb4nh9LySwYfeYPLGXB771pTrJ98MBo Fc72jXXZIzo9lVzrwiVEptnYAGNPIlrFPbxnEtkas3HMH/b6eKK1qsrrjfWecP0l0vXu UO4XkJau/Uqa4W4JzHbjVGmeYMUIlrO8cxuX5Qyu4/XyFcuZ0dVoQXZahyhH1VG5s+a+ YMnTYNhSM/bU7Feg7luvNJ0WXBuc4ZAEBOdQBQ17aB+tWU3Gr8dNNrqjRp7NtkQB1B7U tk7CepVIa2pvgYnwxPmNMdBYdRZDJM/X4wqrN2wGSRXu/TgUcVlGWIGXUY4xQl5T/3ke aOsQ== MIME-Version: 1.0 Received: by 10.180.105.130 with SMTP id gm2mr6053285wib.6.1342279720514; Sat, 14 Jul 2012 08:28:40 -0700 (PDT) Received: by 10.216.178.4 with HTTP; Sat, 14 Jul 2012 08:28:40 -0700 (PDT) In-Reply-To: References: <5000BF44.3080907@sugarcrm.com> Date: Sat, 14 Jul 2012 09:28:40 -0600 Message-ID: To: Paul Dragoonis Cc: Anthony Ferrara , Stas Malyshev , Brandon Wamboldt , Andrew Faulds , internals Content-Type: multipart/alternative; boundary=f46d04428104ee32ae04c4cbd950 Subject: Re: [PHP-DEV] Re: array_last_key() function From: john.lesueur@gmail.com (John LeSueur) --f46d04428104ee32ae04c4cbd950 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Jul 14, 2012 at 4:34 AM, Paul Dragoonis wrote: > On Sat, Jul 14, 2012 at 3:04 AM, Anthony Ferrara > wrote: > > Stas, > > > >> 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... > > and it beats doing $var = null; if(isset($array[0])) { $var = $array[0]; } > > Not sure that does the trick(you're pulling values, not keys, and assuming 0-based array), but... What about reset(array_keys($array)); or end(array_keys($array)); which only makes copies of the keys? or even better key(array_slice($array, 0, 1, true)); or key(array_slice($array,-1,1,true)); which makes a copy of one element of the array? I'm of the opinion that we mostly have enough array_* functions, and new ones have to provide a significant advantage to be accepted. If these functions are significantly faster than the alternatives, then perhaps they have merit, but they seem like convenience functions, rather than fundamentals. John --f46d04428104ee32ae04c4cbd950--