note 38379 deleted from function.current by nlopess
| From: | nlopess@php.net | Date: | Fri, 02 Jan 2004 11:36:18 +0000 |
| Subject: | note 38379 deleted from function.current by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62773@lists.php.net to get a copy of this message | ||
Note Submitter: sam@bigroomstudios.com
----
Here is a function that sets the current pointer of an array to a given key. Call me crazy but I
couldn't find a built in one. This is handy if you want to jump into the middle of an array and
then go forward or back using prev() and next(). If someone has a way to do this without traversing
I'd love to know what it is.
<?php
//set the pointer of an array to the given key
function array_set_current(&$array, $key){
while(current($array)){
if(key($array) == $key){
break;
}
next($array);
}
}
?>
Peace,
Sam