php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46210 Strange ouput after using each function
Submitted: 2008-10-01 12:42 UTC Modified: 2008-10-01 12:49 UTC
From: anvergdr at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.6 OS: windows xp
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: anvergdr at gmail dot com
New email:
PHP Version: OS:

 

 [2008-10-01 12:42 UTC] anvergdr at gmail dot com
Description:
------------
I assigned an associated array using each function from an array. But when using the list function the first element is not displaying. When commenting the second associated array which was created using the each function the code outputs all the values.

Reproduce code:
---------------
<?php
	
	$Greetings = array(	'First'=>'January', 'Second'=>'February', 'Third'=>'March',	'Fourth'=>'April', 'Fifth'=>'May');
	
	$CurrentGreeting = each($Greetings);
	
	while(list($Language, $Greeting)= each($Greetings))
		{
			echo $Language . ' is  ' .$Greeting ."<br />";
		}	
		
?>

Expected result:
----------------
First is January
Second is February
Third is March
Fourth is April
Fifth is May


Actual result:
--------------
Second is February
Third is March
Fourth is April
Fifth is May


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-01 12:49 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The manual clearly states you need to use reset() to reset the internal array pointer after each() if you want to traverse the array again.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 01:01:33 2024 UTC