variable modified in foreach loop does not stay
<p>I have this function that takes in an array and use a variable to count the total number of students. However when I print the variable $number, it still returns me zero. I am very sure the if statement was invoked. How can I update $number in the foreach loop if the method I mention does not work?</p>

<pre><code>function blah($array)
{

    $number = 0;

    foreach ($array as $value)
    {
    if ($value['class'] == 1)
    $number += $value['nbStudents'];  //if statement was invoked
    print($number);  //returns the correct non-zero value
    }

    print($number);  //returns zero
}
</code></pre>
