Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47366 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45209 invoked from network); 17 Mar 2010 16:13:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Mar 2010 16:13:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=felix.devliegher@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=felix.devliegher@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: felix.devliegher@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:53125] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/A7-05162-AAFF0AB4 for ; Wed, 17 Mar 2010 11:13:31 -0500 Received: by wyb36 with SMTP id 36so619690wyb.29 for ; Wed, 17 Mar 2010 09:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:mime-version :content-type:from:in-reply-to:date:cc:content-transfer-encoding :message-id:references:to:x-mailer; bh=z5JpEioc8FbQ0ZnsLhChSI696XLeCsG3j1pxvREaG0Q=; b=dcELBry51YD4VSrwqc16VO34+2ESb7y8FIkRUsFxDb+trPh6JBcwsbpRYu7Q+9ha4b rHtjF+cFF6QVhIYmhI5DOaAhUtbx5gmnHqAsA67aN9wkX1LmX1TC7xij24izZLSlsS6I cXjb7HADLkc66MJuh8bDIdsx2Rg4c7u/enh2U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; b=F/qyWoEz2Ip7hILNQweR3E2+eP2KycbAefcma2tFonyE2Ms6yh2IMKtb71qG8gTYkM 7Inoy75UNUkDd6pszzbmkVjUJvYRkgd8TnNnizZ1M6eeyvaIzhcrp141TBVSTVKWMLJI e095i5HP7o1WLuIeC+fTBotSEGhyAh59dw4KY= Received: by 10.216.87.134 with SMTP id y6mr396585wee.20.1268842407560; Wed, 17 Mar 2010 09:13:27 -0700 (PDT) Received: from [192.168.2.10] (94-225-45-193.access.telenet.be [94.225.45.193]) by mx.google.com with ESMTPS id g11sm1363882gve.3.2010.03.17.09.13.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 17 Mar 2010 09:13:26 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset=us-ascii In-Reply-To: Date: Wed, 17 Mar 2010 17:13:24 +0100 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <72EAF587-5446-4285-8266-45D95AEAC471@gmail.com> References: <6E76B52E-7543-4F09-A948-A7910513B548@gmail.com> To: Patrick ALLAERT X-Mailer: Apple Mail (2.1077) Subject: Re: [PHP-DEV] array_seek function From: felix.devliegher@gmail.com (Felix De Vliegher) On 17-mrt-2010, at 17:00, Patrick ALLAERT wrote: > 2010/3/16 Felix De Vliegher : >> Hi all >>=20 >> 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 =3D 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) >>=20 >> Basically you can use it like this: >> $input =3D 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 >>=20 >> I was wondering if it's useful to add this to the family of array = functions. I know there is a somewhat similar thing in SPL = (ArrayIterator::seek), but that doesn't work exactly like what I was = aiming for. >>=20 >> Attached is a patch for the function against the 5.3 branch. If = approved, I could add it to svn + testcases + docs. Feedback please :-) >>=20 >>=20 >> Kind regards, >> Felix >=20 > Hi Felix, >=20 > What about adding a new int parameter to PHP array function: next() > and prev() instead of adding a new one? Hi Patrick That's of course possible, but that would only allow seeking to a = relative position to where the array pointer is at that moment. The = functionality also gets a bit ambiguous by adding an optional parameter. = You're not going to the next or prev position of the array anymore. And I think functions like next, prev, current etc should be kept easy = to use. If you want seek-like functionality, use the designated array = function for that (if this one should make it into php, that is). Cheers, Felix=