Re: Possible foreach bug; seeking advice to isolate the problem

From: Date: Sat, 23 Oct 2010 05:50:08 +0000
Subject: Re: Possible foreach bug; seeking advice to isolate the problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-309035@lists.php.net to get a copy of this message
Gary wrote: >Better. I can tell you how to solve it: > $a = array('a', 'b','c'); > foreach($a as &$row){ > //you don't have to do anything here > } > unset($row); // <----<<< THIS IS KEY! > print_r($a); > foreach($a as $row){ > echo "<br />".$row; > } > print_r($a); I see what you're doing now: unsetting the variable, not the array element referenced by the variable. You're right, it does work. It's not exactly better than knowing what's wrong, though... it's different. I already had a workaround, although it was not quite as elegant. My desire now is to find out whether the behavior I described is due to something I don't understand about PHP, or to a bug. If it's something I don't understand, I want to understand it. If it's a bug, I want to report it.

« previous php.general (#309035) next »