<?php
function array_average($array) {
$retval = FALSE;
if(is_array($array) && count($array))
$retval = array_sum($array) / count($array);
return $retval;
}
$scores = array('R' => 8.5, 'Jan' => 9.8, 'Terry' => 8.0);
printf("<p>There are %d scores, totaling %.2f and averaging %.2f.</p>",
count($scores), array_sum($scores), array_average($scores));
?>
|