Variable Not Showing When Function Called Early In Script
<p>Any help is appreciated. I cannot seem to get the value of $sum if I call showSum() before the function...</p>

<p>EXAMPLE 1: (this works fine)</p>

<pre><code>[main code here]

$sum = $valueObtainedAfterWhileLoop;

function showSum(){
global $sum;

return $sum;
}
echo getSum();
</code></pre>

<hr>

<p>EXAMPLE 2: (this does not work - no error is returned, but no value is printed to the screen)</p>

<pre><code>echo getSum();

[main code here]

$sum = $valueObtainedAfterWhileLoop;

function showSum(){
global $sum;

return $sum;
}
</code></pre>

<p>I need to use the value of $sum at the top of the page. What can I do?</p>

<hr>
