RE: [PHP-DEV] PHP 4.0 Bug #4999: foreach() does not act like each (), uses a copy

From: Date: Tue, 13 Jun 2000 07:51:37 +0000
Subject: RE: [PHP-DEV] PHP 4.0 Bug #4999: foreach() does not act like each (), uses a copy
Groups: php.dev 
Request: Send a blank email to php-dev+get-21189@lists.php.net to get a copy of this message
Maybe I´ve misunderstood things, sorry if so. If foreach() uses a copy, then it shouldn´t manipulate the array pointer right? But it does. Executing the code below results in: 0123456 the while loop doesn´t output anything. <? $a=array(0,1,2,3,4,5,6); foreach($a as $val) { print $val; } echo '<br>'; while(list($k, ) = each($a)) { echo $k; } ?> regards --marten > -----Original Message----- > From: waldschrott@kiffen.de [mailto:waldschrott@kiffen.de] > Sent: Tuesday, June 13, 2000 8:53 AM > To: php-dev@lists.php.net > Subject: [PHP-DEV] PHP 4.0 Bug #4999: foreach() does not act like > each(), uses a copy > > > From: waldschrott@kiffen.de > Operating system: win2000/all > PHP version: 4.0 Latest CVS (13/06/2000) > PHP Bug Type: Documentation problem > Bug description: foreach() does not act like each(), uses a copy > > 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; } > > ?> >

« previous php.dev (#21189) next »