note 26760 added to control-structures.foreach

From: Date: Tue, 12 Nov 2002 00:49:15 +0000
Subject: note 26760 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-39358@lists.php.net to get a copy of this message
I found it impossible to edit values of references like this: $een = 1; $twee = 2; $drie = 3; $lst = array(&$een, &$twee, &$drie); foreach ($lst as $c) $c += 10; foreach ($lst as $c) echo("$c \n"); this gives "1 2 3" not "11 12 13" as i would have liked it to I think this has to do with 'foreach' working on a copy of the array.. Besides "foreach ($lst as &$c)" won't work either.. it isn't accepted by the php parser. The best solution to handle this array of references is with a while loop. -- http://www.php.net/manual/en/control-structures.foreach.php http://master.php.net/manage/user-notes.php?action=edit+26760 http://master.php.net/manage/user-notes.php?action=delete+26760 http://master.php.net/manage/user-notes.php?action=reject+26760

« previous php.notes (#39358) next »