Re: scope problem

From: Date: Fri, 05 Mar 2004 16:13:36 +0000
Subject: Re: scope problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-179581@lists.php.net to get a copy of this message
can you post something that would run on php? Larry Brown wrote:
Apparently I'm having some kind of meltdown here. Can anyone explain the logic behind why the following variable has the original value and how I can pull/push the value to access it at the end? while loop { $variable = 100; while loop { switch($othervar) { case 1: $variable = $variable + 100; break; case 2: $variable = $variable + 200; break; case 3: $variable = $variable + 300; break; } echo $variable."<br>"; } echo "<br>The final value is ".$variable."<br>"; } This gives values something to the tune of... 200 400 700 100 I usually have variables set outside of a while loop that increment based on the contents of the loop and I could swear that they hold the value on the other side of the loop. I don't usually use break; in my scripts unless I'm using switch. However, I would think that if using break was throwing me, that the value wouldn't print on each cycle of the loop. TIA Larry
-- André Cerqueira

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.general (#179581) next »