Re: Average Number For Math Functions
| From: | Andrew Brampton | Date: | Fri, 30 Aug 2002 01:34:20 +0000 |
| Subject: | Re: Average Number For Math Functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114584@lists.php.net to get a copy of this message | ||
I can't seem to see a pre-built functions but here is one I just wrote in
my email client:
function average($numberArray) {
$sum = 0;
for ($i=0;$i<count($numberArray);$i++)
$sum += $numberArray[$i];
return $sum / count($numberArray);
}
echo average(array (1,2,3,4,5));
Hope this helps :)
Andrew
----- Original Message -----
From: "JohnP" <aerc@aerc.biz>
To: <php-general@lists.php.net>
Sent: Friday, August 30, 2002 1:55 AM
Subject: [PHP] Average Number For Math Functions
Ok I looked at all the math functions for PHP but saw no way of returning
the average of a set of numbers - I plan on using this for a rating
system - any help?
--
John