note 31737 added to ref.array

From: Date: Fri, 02 May 2003 01:10:52 +0000
Subject: note 31737 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-47368@lists.php.net to get a copy of this message
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); } } } -- http://www.php.net/manual/en/ref.array.php http://master.php.net/manage/user-notes.php?action=edit+31737 http://master.php.net/manage/user-notes.php?action=delete+31737 http://master.php.net/manage/user-notes.php?action=reject+31737

« previous php.notes (#47368) next »