php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #4999 foreach() does not act like each(), uses a copy
Submitted: 2000-06-13 08:52 UTC Modified: 2000-07-02 02:22 UTC
From: waldschrott at kiffen dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0 Latest CVS (13/06/2000) OS: win2000/all
Private report: No CVE-ID: None
 [2000-06-13 08:52 UTC] waldschrott at kiffen dot de
It should be documented that foreach() uses a copy of the passed array, being completely independent from the original $a - for the reason that each() (and next() and so on) works directly on the arrays pointer

<?php
$a=array(0,1,2,3,4,5,6);
foreach ($a AS $val)	{
	print $val;
	list(,$val)=each($a);
	list(,$val)=each($a);
	next($a);
	print $val;  }

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-02 02:22 UTC] sterling at cvs dot php dot net
Fixed in CVS.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Jun 18 05:00:01 2026 UTC