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

From: Date: Wed, 20 Oct 2010 12:51:52 +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-308884@lists.php.net to get a copy of this message
On Wed, 20 Oct 2010 08:37:55 +0200, php-general@garydjones.name (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 don't quite I follow this. I'll have to try it when I have time (I hope later today) to understand what you're proposing. Unfortunately it won't work in this, for one or two reasons. The first possible reason is that I'm not referencing the "as" variable with an ampersand. If I'd have to add one to fix this problem, it might cause other problems. The second (definite) reason is that I can't read the array destructively (with an unset). The problem occurs in code that is preparing the array for later read-only use, so that would be self-defeating!

« previous php.general (#308884) next »