> -----Original Message-----
> From: Felix De Vliegher [mailto:felix.devlieg...@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


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to