I've got an array of objects that I'm trying to walk through and change each object. Something like:
while(list($key,$value)=each($objects)) {
$value->changeMe('foo');
}
The problem with the above is that it appears that each returns a copy of the object in the array, so changing it inside the loop with $value->changeMe doesn't change the object in the $objects array.
I've tried:
while(list($key,)=each($objects)) {
$value =& $objects[$key];
$value->changeMe('foo');
}
This seems to work. I'm looking for confirmation that I'm not missing something, and hopefully a more elegant way to do this. I was hoping that
while(list($key,&$value)=each($objects)) {
...
would work, but it yields a parse error.
PHP 4.0.2.
Thanks.
Padraic