php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39255 foreach only shows last item
Submitted: 2006-10-25 14:47 UTC Modified: 2006-10-26 16:57 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: PK at KoffieHosting dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.1.6 OS: ISS 6.0
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: PK at KoffieHosting dot com
New email:
PHP Version: OS:

 

 [2006-10-25 14:47 UTC] PK at KoffieHosting dot com
Description:
------------
FastCGI (PHP5) on ISS 6.0: the foreach only shows the last item.

Reproduce code:
---------------
foreach ($_POST['Boxes'] as $Key => $Value);
{
echo '['.$Key.'] => '.$Value;
}

Note that this does work 100%:

while (list($What, $Amount) = each($_POST['Boxes']))
{
echo '['.$Key.'] => '.$Value;
}

Expected result:
----------------
     [4] => 0 
     [2] => 0 
     [3] => 1
     [6] => 0
     [1] => 0
     [5] => 0

Actual result:
--------------
     [5] => 0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-25 14:49 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-10-25 14:53 UTC] PK at KoffieHosting dot com
Unfortunately I can not upgrade that server.
 [2006-10-25 15:02 UTC] tony2001@php.net
No need to upgrade the server, just put it in some other directory and try it.
 [2006-10-25 15:04 UTC] PK at KoffieHosting dot com
I don't have enough rights on that machine (as it is not hosted with us) to try that.
 [2006-10-26 16:28 UTC] phpbugs at thequod dot de
Remove the ";" at the end of the foreach() line.

You have a foreach loop that does nothing and then the 
echo uses the last elements.

This should work:

foreach ($_POST['Boxes'] as $Key => $Value)
{
echo '['.$Key.'] => '.$Value;
}
 [2006-10-26 16:57 UTC] tony2001@php.net
Good catch, thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 14:01:33 2025 UTC