Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27286 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96778 invoked by uid 1010); 5 Jan 2007 17:29:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 96763 invoked from network); 5 Jan 2007 17:29:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2007 17:29:27 -0000 Authentication-Results: pb1.pair.com header.from=andrei@gravitonic.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andrei@gravitonic.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain gravitonic.com from 204.11.219.139 cause and error) X-PHP-List-Original-Sender: andrei@gravitonic.com X-Host-Fingerprint: 204.11.219.139 lerdorf.com Linux 2.5 (sometimes 2.4) (4) Received: from [204.11.219.139] ([204.11.219.139:44918] helo=lerdorf.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/BD-01582-6FA8E954 for ; Fri, 05 Jan 2007 12:29:27 -0500 Received: from [66.228.175.145] (borndress-lm.corp.yahoo.com [66.228.175.145]) (authenticated bits=0) by lerdorf.com (8.13.8/8.13.8/Debian-3) with ESMTP id l05HTOQU013356; Fri, 5 Jan 2007 09:29:24 -0800 In-Reply-To: <76AD94BE-DD27-490D-88F8-8D0EC4A2C4E6@zort.net> References: <76AD94BE-DD27-490D-88F8-8D0EC4A2C4E6@zort.net> Mime-Version: 1.0 (Apple Message framework v624) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-ID: <8fd0bffd7fa15d43ac8943401e80b612@gravitonic.com> Content-Transfer-Encoding: 7bit Cc: PHP internals Date: Fri, 5 Jan 2007 09:29:58 -0800 To: John Bafford X-Mailer: Apple Mail (2.624) Subject: Re: [PHP-DEV] [PATCH] New functions: array_key_index(), array_first(), array_last() From: andrei@gravitonic.com (Andrei Zmievski) These functions seem to replace only a couple lines of code at best, especially array_first() and array_last(). I don't think the cost of keeping up the code/docs for the new functions warrants their inclusion. -Andrei On Jan 4, 2007, at 9:49 PM, John Bafford wrote: > Hello, > > Attached is a patch and corresponding test file I would like to submit > for inclusion in PHP. I would like this patch to be included in PHP > 5.2.1, as it is entirely new code (and thus shouldn't cause > regressions), but as RC2 was just released earlier today, I understand > if it must wait until PHP 5.2.2. > > This patch implements three new functions, as described below. > > mixed array_key_index(array input, int index [, mixed value]) > Return the array's index'th key (and optionally, value) > > mixed array_first(array input [, mixed value]) > Return the array's first key (and optionally, value) > This is equivalent to array_key_index($input, 0 [, $value]); > > mixed array_last(array input [, mixed value]) > Return the array's last key (and optionally, value) > This is equivalent to array_key_index($input, -1 [, $value]); > > array_first() is a non-destructive way to get the first key (and > value, if requested) from an array. array_first() is intended to > replace code similar to the following: > foreach($arr as $key => $val) break; > reset($arr); $key = key($arr); > reset($arr); list($key, $val) = each($arr); > $key = array_keys($arr); $key = $key[0]; > > array_last() is the obvious counterpart to array_first(), returning > the last key (and value, if requested) from an array. > > array_first() and array_last() are implemented via array_key_index(), > which returns a key based on its order in the array. The index > parameter functions similarly to substr()'s start parameter (>= 0 > start from the beginning of the array, <= -1 start from the end.) > > All three functions leave the original array unmodified. In the event > of an error (invalid parameters, or attempting to seek past the end of > the array), all three functions return NULL and leave $value > unchanged. > > Please let me know if you have any comments. > > Thanks, > > -John > > > -- > John Bafford > dshadow@zort.net > http://www.dshadow.com/ > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php