AndyL
08-11-2004, 05:57 PM
Quick Question:
Am I right in thinking that a variable/value in a While loop will cease to exist when the While loop has finished?
If this is the case how can I 'capture' a particular variable/value when iterating through the While loop and then use it OUTSIDE of the While loop?
while(list($var, $val) = each($HTTP_POST_VARS))
{
if ("Yes" == $val) // i.e. if Nil_Return == Yes
{
echo "$var: $val<BR>";
echo "Name: " . $Name . "<BR>";
echo "Date_Time_of_Completion_of_Form: " . date('d-m-Y H:i:s') . "<BR>";
break;
}
else // i.e. if Nil_Return == No
{
echo "$var: $val<BR>";
if ("Email_Address" == $var)
{
echo "Email_Address $val";
}
}
}
The line:
echo "$var: $val<BR>";
in the 'Else' statement renders the screen with a load of info and I wish to access one of those $val (e.g. "xxx@domain.com") for the respective $var (i.e. "Email_Address") and use it outside of the While loop.
I.E. what's the best way to get a variable from within a While loop for use outside of the While loop [when it's finished iterating]?
Thanks,
Andy
Am I right in thinking that a variable/value in a While loop will cease to exist when the While loop has finished?
If this is the case how can I 'capture' a particular variable/value when iterating through the While loop and then use it OUTSIDE of the While loop?
while(list($var, $val) = each($HTTP_POST_VARS))
{
if ("Yes" == $val) // i.e. if Nil_Return == Yes
{
echo "$var: $val<BR>";
echo "Name: " . $Name . "<BR>";
echo "Date_Time_of_Completion_of_Form: " . date('d-m-Y H:i:s') . "<BR>";
break;
}
else // i.e. if Nil_Return == No
{
echo "$var: $val<BR>";
if ("Email_Address" == $var)
{
echo "Email_Address $val";
}
}
}
The line:
echo "$var: $val<BR>";
in the 'Else' statement renders the screen with a load of info and I wish to access one of those $val (e.g. "xxx@domain.com") for the respective $var (i.e. "Email_Address") and use it outside of the While loop.
I.E. what's the best way to get a variable from within a While loop for use outside of the While loop [when it's finished iterating]?
Thanks,
Andy