php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5704 two nested foreach loops on the same array stop prematurely.
Submitted: 2000-07-20 18:39 UTC Modified: 2000-07-20 20:47 UTC
From: bailey at mcs dot anl dot gov Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0.0 OS: Redhat Linux 6.1, kernel 2.2.15
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bailey at mcs dot anl dot gov
New email:
PHP Version: OS:

 

 [2000-07-20 18:39 UTC] bailey at mcs dot anl dot gov
<?php

  $config = array(  1  => "foo",                                     
                    2  => "bar",
                    3  => "far",
  );

  foreach ($config as $resource => $value) {
    echo $resource, ":<br>\n";
    foreach ($config as $resource2 => $value2) {
      echo "$resource2<br>\n";
    }
  }  
     
?>

this script will display the following webpage:

1:
1
2
3

It should display this:

1:
1
2
3
2:
1
2
3
3:
1
2
3

This is a rather severe error, I think.

We have a pretty basic setup, no obscure modules compiled in or anything.

Thanks,
Alan

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-20 20:47 UTC] sterling at cvs dot php dot net
You need to reset() the array manually.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 17:00:01 2026 UTC