On 16 March 2010 13:30, Felix De Vliegher <felix.devlieg...@gmail.com> wrote: > 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 > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
Maybe not as efficient as it could be but ... <?php $input = array('One' => 'Itchy', 'Two' => 'Knee', 'Three' => 'San', 'Four' => 'She'); echo @reset(array_keys(array_values($input), 'Knee')); Richard. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php