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

From: Date: Thu, 12 Apr 2001 09:43:53 +0000
Subject: RE: [PHP] foreach vs. while(list() = each())
Groups: php.general 
Request: Send a blank email to php-general+get-48275@lists.php.net to get a copy of this message
you can't nest foreach as you should be able to. Ecah foreach is supposed to have it's own pointer in the array, but it doesn't ... this is a known bug. 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: Yasuo Ohgaki [mailto:yohgaki@hotmail.com] > Sent: 12 April 2001 02:37 > To: php-general@lists.php.net > Subject: Re: [PHP] foreach vs. while(list() = each()) > > > One apparent problem with foreach() is it can misbehave code > as follows. > (4.0.4pl1, 4.0.5RC6) > > function foo($a) { > foreach ($a[0] as $k => $v) { > echo $k.$v; > } > } > > $a = 'abc'; > foo($a); > > You'll get 'server not found' or browser waiting forever with > this code. > (If you don't, please let me know) > > String can be accessed like array, but foreach does not > handle invalid parameter > well. > While() does not misbehave with equivalent code. > > Regards, > -- > Yasuo Ohgaki > > > "Joe Stump" <miester@php.net> wrote in message > news:20010411134931.C3680@zorka.com... > > What are the differences in these? I know with while() you > have to reset() the > > array afterwards, but foreach() you don't. Also foreach() > appears to be quite > > a bit faster. > > > > My main question is there ANY difference in how these two > loop through the > > array. > > > > --Joe > > > > > > > > > /************************************************************* > *****************\ > > * Joe Stump - PHP/SQL/HTML Developer > * > > * http://www.care2.com - > > http://www.miester.org - http://gtk.php-coder.net * > * "Better to double your money on mediocrity than lose it all on a dream." * > \*************************************************************************** ***/ > > -- > 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 >

« previous php.general (#48275) next »