Re: Strange foreach reference issue

From: Date: Sun, 08 Jan 2012 00:44:29 +0000
Subject: Re: Strange foreach reference issue
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-316217@lists.php.net to get a copy of this message
On 12-01-07 07:30 PM, Tim Behrendsen wrote:
When you use an ampersand on the variable, that creates a reference to the array elements, allowing you to potentially change the array elements themselves (which I'm not doing here). http://www.php.net/manual/en/control-structures.foreach.php I do notice in the manual that it says, "Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset()." But that doesn't really explain why it contaminates the next foreach loop in such an odd way. You would think that the $row in the second loop would be assigned a non-reference value. Tim Tim,
You are using the &$variable in an unintended (by PHP designers), and I suggest undefined manner. So the outcome cannot, but definition be explained. Was this intended, and what were you trying to accomplish? Stephen

« previous php.general (#316217) next »