Reset the Internal Pointer Value of a PHP Array (ArrayObject)

tuacumaney

New Member
Consider a simple PHP ArrayObject with two items.\[code\]$ao = new ArrayObject();$ao[] = 'a1'; // [0] => a1$ao[] = 'a2'; // [1] => a2\[/code\]Then delete the last item and add a new item.\[code\]$ao->offsetUnset(1);$ao[] = 'a3'; // [2] => a3\[/code\]I'd very much like to be able to have 'a3' be [1].How can I reset the internal pointer value before I add 'a3'?I have a simple function that does this but I'd rather not copy the array if I don't have to.\[code\]function array_collapse($array) { $return = array(); while ($a = current($array)) { $return[] = $a; next($array); } return $return;}\[/code\]
 
Back
Top