Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47308 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9593 invoked from network); 16 Mar 2010 14:13:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2010 14:13:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=cschneid@cschneid.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=cschneid@cschneid.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cschneid.com from 195.226.6.51 cause and error) X-PHP-List-Original-Sender: cschneid@cschneid.com X-Host-Fingerprint: 195.226.6.51 darkcity.gna.ch Linux 2.6 Received: from [195.226.6.51] ([195.226.6.51:60261] helo=mail.gna.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/FE-15129-DE19F9B4 for ; Tue, 16 Mar 2010 09:13:02 -0500 Received: from localhost (localhost [127.0.0.1]) by darkcity.gna.ch (Postfix) with ESMTP id 154601833F0; Tue, 16 Mar 2010 15:12:59 +0100 (CET) X-Virus-Scanned: amavisd-new at gna.ch Received: from mail.gna.ch ([127.0.0.1]) by localhost (gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CACLZgjAF+29; Tue, 16 Mar 2010 15:12:58 +0100 (CET) Received: from [192.168.1.72] (80-219-163-117.dclient.hispeed.ch [80.219.163.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 9F9551833EB; Tue, 16 Mar 2010 15:12:57 +0100 (CET) Message-ID: <4B9F91E9.1000100@cschneid.com> Date: Tue, 16 Mar 2010 15:12:57 +0100 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Felix De Vliegher CC: PHP internals References: <6E76B52E-7543-4F09-A948-A7910513B548@gmail.com> In-Reply-To: <6E76B52E-7543-4F09-A948-A7910513B548@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: array_seek function From: cschneid@cschneid.com (Christian Schneider) Felix De Vliegher wrote: > Hi all > > I recently needed seek functionality in arrays, and couldn't find it > in the regular set of array functions, so I wrote a function for it. > Seek = getting an array value based on the position (or offset, if you > want to call it like that), and not the key of the item) > > Basically you can use it like this: > $input = array(3, 'bar', 'baz'); > echo array_seek($input, 2); // returns 'baz' > echo array_seek($input, 0); // returns 3 > echo array_seek($input, 5); // returns NULL, emits an out of range warning I thinks the user space implementation function array_seek($array, $pos) { $a = array_values($array); return $a[$pos]; } is simple enough to not add a native function for this. It might not be the most efficient way to do it but I doubt that it is something done frequently enough to justify another native function. My 2 cents, - Chris