Nesting 'foreach ()'

From: Date: Mon, 29 Jan 2001 14:10:37 +0000
Subject: Nesting 'foreach ()'
Groups: php.general 
Request: Send a blank email to php-general+get-37233@lists.php.net to get a copy of this message
according to the online refernce foreach() doesn't change the array pointer. However the following code: $fred = array(1,2,3,4,5,6); foreach ($fred as $fred1) { foreach ($fred as $fred2) echo "$fred1 : $fred2<br>"; }; returns: 1 : 1 1 : 2 1 : 3 1 : 4 1 : 5 1 : 6 and stops there, implying that the second foreach() is interfering with the first. I've got around this in my actual case by creating two arrays and adding to the second as well as the first, but this won't always be as convenient. Is this a known bug or is the manual wrong? ... by the way $fred = array(1,2,3,4,5,6); $fred2 = $fred; foreach ($fred as $fred1) { foreach ($fred2 as $fred2) echo "$fred1 : $fred2<br>"; }; ... doesn't work either which would normally imply that $fred2 is a pointer to $fred rather than a copy. Can this be the case? I am using version 4.0.0 Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html

« previous php.general (#37233) next »