Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47347 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53513 invoked from network); 16 Mar 2010 22:27:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2010 22:27:06 -0000 Authentication-Results: pb1.pair.com header.from=jared.williams1@ntlworld.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jared.williams1@ntlworld.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ntlworld.com designates 81.103.221.47 as permitted sender) X-PHP-List-Original-Sender: jared.williams1@ntlworld.com X-Host-Fingerprint: 81.103.221.47 mtaout01-winn.ispmail.ntl.com Solaris 10 (beta) Received: from [81.103.221.47] ([81.103.221.47:27704] helo=mtaout01-winn.ispmail.ntl.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/5A-15129-3B500AB4 for ; Tue, 16 Mar 2010 17:27:05 -0500 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100316222655.DMBB4204.mtaout01-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com>; Tue, 16 Mar 2010 22:26:55 +0000 Received: from p2 ([82.0.126.169]) by aamtaout03-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20100316222655.XLDT2093.aamtaout03-winn.ispmail.ntl.com@p2>; Tue, 16 Mar 2010 22:26:55 +0000 To: "'Felix De Vliegher'" , "'PHP internals'" Date: Tue, 16 Mar 2010 22:29:48 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 In-Reply-To: <6E76B52E-7543-4F09-A948-A7910513B548@gmail.com> Thread-Index: AcrFDRRXBym0mL02SSKb3pGkxpprGQASuTsg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325 Message-ID: <20100316222655.XLDT2093.aamtaout03-winn.ispmail.ntl.com@p2> X-Cloudmark-Analysis: v=1.1 cv=W3tOLUehizD4qj6VhtReFuw5MKb8d+XqjIxlDsIazEA= c=1 sm=0 a=SvoWcx1iAeoA:10 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=QC2xVoUTSQUoE2CCIjwA:9 a=Ebx6Hu363Vv7zQtl8zzRbvQBJN0A:4 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Subject: RE: [PHP-DEV] array_seek function From: jared.williams1@ntlworld.com ("Jared Williams") References: <6E76B52E-7543-4F09-A948-A7910513B548@gmail.com> > -----Original Message----- > From: Felix De Vliegher [mailto:felix.devliegher@gmail.com] > Sent: 16 March 2010 13:31 > To: PHP internals > Subject: [PHP-DEV] array_seek function > > 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 > Remember doing something like this in the past... $input = array(3, 'bar', 'baz'); $iterator = new ArrayIterator($input); $iterator->seek(2); echo $iterator->current(); $iterator->seek(0); echo $iterator->current(); $iterator->seek(5); // throws OutOfBoundsException Though a specific function does make sense, imo. Jared