scope problem
| From: | Larry Brown | Date: | Fri, 05 Mar 2004 16:01:39 +0000 |
| Subject: | scope problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-179578@lists.php.net to get a copy of this message | ||
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