Re: Nesting 'foreach ()'

From: Date: Tue, 30 Jan 2001 04:24:06 +0000
Subject: Re: Nesting 'foreach ()'
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37236@lists.php.net to get a copy of this message
Perhaps : http://php.net/ChangeLog-4.php Under 4.0.2 it says : "Fixed problem with nested foreach()'s. (Andi, Zend Engine)" philip On Tue, 30 Jan 2001, Chris Fry wrote: > Tim, > > Works fine in 4.04pl1 on NT. > > I think you should have curly braces round the inner foreach as well? > > $fred = array(1,2,3,4,5,6); > foreach ($fred as $fred1) > { foreach ($fred as $fred2) { > echo "$fred1 : $fred2<br>"; > } > }; > > > Chris Fry > > Tim Ward wrote: > > > 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 > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > Chris Fry > Quillsoft Pty Ltd > Specialists in Secure Internet Services and E-Commerce Solutions > 10 Gray Street > Kogarah > NSW 2217 > Australia > > Phone: +61 2 9553 1691 > Fax: +61 2 9553 1692 > Mobile: 0419 414 323 > eMail: chris@quillsoft.com.au > http://www.quillsoft.com.au > > You can download our Public CA Certificate from:- > https://ca.secureanywhere.com/htdocs/cacert.crt > > ********************************************************************** > > This information contains confidential information intended only for > the use of the authorised recipient. If you are not an authorised > recipient of this e-mail, please contact Quillsoft Pty Ltd by return > e-mail. > In this case, you should not read, print, re-transmit, store or act > in reliance on this e-mail or any attachments, and should destroy all > copies of them. > This e-mail and any attachments may also contain copyright material > belonging to Quillsoft Pty Ltd. > The views expressed in this e-mail or attachments are the views of > the author and not the views of Quillsoft Pty Ltd. > You should only deal with the material contained in this e-mail if > you are authorised to do so. > > This notice should not be removed. > > >

« previous php.general (#37236) next »