Re: array_seek function
| From: | Felix De Vliegher | Date: | Tue, 16 Mar 2010 23:23:23 +0000 |
| Subject: | Re: array_seek function | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47349@lists.php.net to get a copy of this message | ||
Hi
As SEEK_END only makes sense with zero or negative offsets (for arrays anyway), I've come up
with an implementation for SEEK_END:
http://phpbenelux.eu/array_seek.patch.txt
So you can do:
$arr = array('a', 'b', 'c', 'd');
echo array_seek($arr, -2, SEEK_END); // outputs 'b'
echo array_seek($arr, 0, SEEK_END); // outputs 'd'
Cheers,
Felix
On 16-mrt-2010, at 19:07, Mikko Koppanen wrote:
> On Tue, Mar 16, 2010 at 4:22 PM, Derick Rethans <derick@php.net> wrote:
>> I was also thinking, can we just make this work just like fseek (with a
>> "whence" parameter) as well? (http://uk3.php.net/fseek)
>
> Hi,
>
> not sure how SEEK_END is supposed to work with arrays but here is
> SEEK_SET and SEEK_CUR (with positive and negative offset)
> http://valokuva.org/~mikko/array_seek_whence.patch.txt
>
> --
> Mikko Koppanen