The returned value from the call \$result = add_this(3,10) is $result
"; print "Note: the values \$n1 and \$n2 do not exist OUTSIDE the function if they are not explictly returned: \$n1 = $n1 and \$n = $n2.
"; //--------------------------------------------------------------------------- /* Let's make this more general. This function will average a set of scores. It doesn't matter how many scores there are (this is dynamic). The array containing the scores can be taken as an input parameter. */ function average_scores($score_array){ $sum = 0; $n = 0; foreach($score_array as $key => $value){ $sum = $sum + $value; $n = $n + 1; } $average = $sum/$n; $average = round($average,2); return $average; } $scores = array(1,1,1,2,3,4,3,4); $results = average_scores($scores); print "Here is the result from averaging 1 1 1 2 3 4 3 4: $results
"; ?>