RE: [PHP] Average Number For Math Functions
| From: | Dave at Sinewaves.net | Date: | Fri, 30 Aug 2002 02:23:10 +0000 |
| Subject: | RE: [PHP] Average Number For Math Functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114583@lists.php.net to get a copy of this message | ||
if i remember 4th grade math class correctly...
<?
$total = 0;
$count = 0;
// get each of the numbers
foreach($array_of_the_numbers as $key => $value)
{
$total += $array_of_the_numbers[$key];
++$count;
}
// wow, that's a toughie!
$average = $total / $count;
// then you could make it pretty
$pretty_average = number_format($average, 1);
?>
booyah. :)
dave
-----Original Message-----
From: JohnP [mailto:aerc@aerc.biz]
Sent: Thursday, August 29, 2002 5:56 PM
To: php-general@lists.php.net
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