note 26556 deleted from language.references by sniper

From: Date: Tue, 30 Sep 2003 01:18:35 +0000
Subject: note 26556 deleted from language.references by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57313@lists.php.net to get a copy of this message
Note Submitter: rking@rmode.com ---- An interesting thing happens when you use a variable that has been set to a reference as the iterated value in foreach statements. Without unset-ing the iterated value variable before the foreach, each iteration will change the content pointed to by the reference. $field = &$someVariable; print $someVariable; // unset($field); // Without this, the following will probably not work they way you want. It will set the contents of $someVariable to the current iterated value. It is left at the end as the last iterated value. foreach ($fields as $field) { print $field; } print $someVariable; // This won't print out the same as the first one

« previous php.notes (#57313) next »