Any help is appreciated. I cannot seem to get the value of $sum if I call showSum() before the function...
EXAMPLE 1: (this works fine)
[main code here]
$sum = $valueObtainedAfterWhileLoop;
function showSum(){
global $sum;
return 开发者_如何学Go$sum;
}
echo getSum();
EXAMPLE 2: (this does not work - no error is returned, but no value is printed to the screen)
echo getSum();
[main code here]
$sum = $valueObtainedAfterWhileLoop;
function showSum(){
global $sum;
return $sum;
}
I need to use the value of $sum at the top of the page. What can I do?
Absolutely nothing. The variable has not been assigned to yet, so there's no value to use. Try calculating it in the function instead.
精彩评论