note 31737 deleted from ref.array by sniper

From: Date: Sat, 18 Oct 2003 18:01:13 +0000
Subject: note 31737 deleted from ref.array by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58824@lists.php.net to get a copy of this message
Note Submitter: brian@stkinternational.com ---- I needed an easy way to move around the internal pointer of an array in place. Here are a couple of functions that I put together out of necessity. /** * @return void * @param $array array * @param offset int * @desc Set internal array pointer to absolute offset */ function aseek(&$array, $offset) { if ( $offset >= 0 ) { reset($array); while (--$offset > 0) { next($array); } } else { end($array); while (++$offset < 0) { prev($array); } } } /** * @return void * @param $array array * @param offset int * @desc Set internal array pointer to relative offset */ function rseek(&$array, $offset) { if ($offset > 0) { while ($offset-- > 0) { next($array); } } else { while ($offset++ < 0) { prev($array); } } }

« previous php.notes (#58824) next »