note 26556 added to language.references
| From: | rking at rmode dot com | Date: | Mon, 04 Nov 2002 21:21:53 +0000 |
| Subject: | note 26556 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38970@lists.php.net to get a copy of this message | ||
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
--
http://www.php.net/manual/en/language.references.php
http://master.php.net/manage/user-notes.php?action=edit+26556
http://master.php.net/manage/user-notes.php?action=delete+26556
http://master.php.net/manage/user-notes.php?action=reject+26556