RE: Re[2]: [PHP] foreach vs. while(list() = each())

2001-04-12 Thread Philip Olson

From Changelog :

  http://php.net/ChangeLog-4.php

  Version 4.0.2   29-Aug-2000 

  Fixed problem with nested foreach()'s. (Andi, Zend Engine) 

Just tested the below example code with 4.0.1 and 4.0.3 and above changed
fixed it.

regards,
philip


On Thu, 12 Apr 2001, Tim Ward wrote:

> not for the same array it can't, the pointer in the first foreach is moved
> by the second one
> 
> try:
> 
> $array = array("a", "b", "c");
> foreach($array as $val1)
> { foreach($array as $val2) echo "$val1:$val2";
> }
> 
> it gives
> a:a
> a:b
> a:c
> then stops, the manual says that the foreach creates it's own pointer which
> it obviously doesn't.
> 
> I can't remember what I was trying to do when I found this, it might have
> been writing a recursive function
> 
>   Tim Ward
>   Senior Systems Engineer
> 
> Please refer to the following disclaimer in respect of this message:
> http://www.stivesdirect.com/e-mail-disclaimer.html
> 
> 
> > -Original Message-
> > From: Maxim Derkachev [mailto:[EMAIL PROTECTED]]
> > Sent: 12 April 2001 16:23
> > To: Tim Ward
> > Cc: [EMAIL PROTECTED]
> > Subject: Re[2]: [PHP] foreach vs. while(list() = each())
> > 
> > 
> > Hello Tim,
> > 
> > Thursday, April 12, 2001, 1:43:53 PM, you wrote:
> > 
> > TW> you can't nest foreach as you should be able to. Ecah 
> > foreach is supposed to
> > TW> have it's own pointer in the array, but it doesn't ... 
> > this is a known bug.
> > 
> > What do you mean? Foreach() can be nested, and it works perfect.
> > 
> >  > $a = array (array (1, 2, 3), array(4,5,6), array(7,8,9));
> > foreach ($a as $k => $first) {
> >   print "$k:\n";
> >   foreach ($first as $second) {
> > print "\t$second\n";
> >   }
> > }
> > ?>
> > 
> > output:
> > 0:
> > 1
> > 2
> > 3
> > 1:
> > 4
> > 5
> > 6
> > 2:
> > 7
> > 8
> > 9
> > 
> > 
> > 
> > 
> > -- 
> > Best regards,
> > Maxim Derkachev mailto:[EMAIL PROTECTED]
> > Symbol-Plus Publishing Ltd.
> > phone: +7 (812) 324-53-53
> > http://www.Books.Ru -- All Books of Russia
> >  
> > 
> > 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: Re[2]: [PHP] foreach vs. while(list() = each())

2001-04-12 Thread Tim Ward

not for the same array it can't, the pointer in the first foreach is moved
by the second one

try:

$array = array("a", "b", "c");
foreach($array as $val1)
{   foreach($array as $val2) echo "$val1:$val2";
}

it gives
a:a
a:b
a:c
then stops, the manual says that the foreach creates it's own pointer which
it obviously doesn't.

I can't remember what I was trying to do when I found this, it might have
been writing a recursive function

Tim Ward
Senior Systems Engineer

Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html


> -Original Message-
> From: Maxim Derkachev [mailto:[EMAIL PROTECTED]]
> Sent: 12 April 2001 16:23
> To: Tim Ward
> Cc: [EMAIL PROTECTED]
> Subject: Re[2]: [PHP] foreach vs. while(list() = each())
> 
> 
> Hello Tim,
> 
> Thursday, April 12, 2001, 1:43:53 PM, you wrote:
> 
> TW> you can't nest foreach as you should be able to. Ecah 
> foreach is supposed to
> TW> have it's own pointer in the array, but it doesn't ... 
> this is a known bug.
> 
> What do you mean? Foreach() can be nested, and it works perfect.
> 
>  $a = array (array (1, 2, 3), array(4,5,6), array(7,8,9));
> foreach ($a as $k => $first) {
>   print "$k:\n";
>   foreach ($first as $second) {
> print "\t$second\n";
>   }
> }
> ?>
> 
> output:
> 0:
> 1
> 2
> 3
> 1:
> 4
> 5
> 6
> 2:
> 7
> 8
> 9
> 
> 
> 
> 
> -- 
> Best regards,
> Maxim Derkachev mailto:[EMAIL PROTECTED]
> Symbol-Plus Publishing Ltd.
> phone: +7 (812) 324-53-53
> http://www.Books.Ru -- All Books of Russia
>  
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]