Re: array_seek function
| From: | Patrick ALLAERT | Date: | Wed, 17 Mar 2010 16:00:00 +0000 |
| Subject: | Re: array_seek function | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47365@lists.php.net to get a copy of this message | ||
2010/3/16 Felix De Vliegher <felix.devliegher@gmail.com>:
> 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 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.
>
> Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn
> + testcases + docs. Feedback please :-)
>
>
> Kind regards,
> Felix
Hi Felix,
What about adding a new int parameter to PHP array function: next()
and prev() instead of adding a new one?
Cheers,
Patrick