[PHP-DEV] Bug #1115: each() should reset array pointers by default? From: charlie <email protected>
Date: 02/02/99

From: charlie <email protected>
Operating system: Linux 2.0.35
PHP version: 3.0.6
PHP Bug Type: Feature/Change Request
Bug description: each() should reset array pointers by default?

each() doesn't reset an array's internal pointer to the first element after executing, which can cause a lot of headaches if you expect that to be the case... I don't know if this is intentional or an oversight, and I can imagine it being either one.

For instance:
<?
echo "<pre>firstpass\n\n";
while ( list( $k, $v ) = each( $GLOBALS ) ) { echo "\n$k => $v"; }
echo "\n\nsecondpass";
while ( list( $k, $v ) = each( $GLOBALS ) ) { echo "\n$k => $v"; }
?>

Will output this to the browser:

  firstpass

  GLOBALS =>
  HTTP_GET_VARS => Array
  HTTP_COOKIE_VARS => Array
  INIT_VERSION => sysvinit-2.69
  TERM => linux
  etc....

  secondpass
  <i>nothing at all...</i>

Of course this can be fixed by adding a call to reset($somearray) after each call to each($somearray), but that doesn't seem very intuitive.

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>