php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #1115 each() should reset array pointers by default?
Submitted: 1999-02-02 17:57 UTC Modified: 2000-05-19 09:52 UTC
From: charlie at k4azl dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 3.0.6 OS: Linux 2.0.35
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: charlie at k4azl dot net
New email:
PHP Version: OS:

 

 [1999-02-02 17:57 UTC] charlie at k4azl dot net
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-19 09:52 UTC] hholzgra at cvs dot php dot net
yeah, how should each() function distinuish betwenn
first and following cycle in while-loop
this ain't possible to implement in a sane way 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 11:01:34 2024 UTC