note 86971 deleted from book.array by peehaa
| From: | peehaa@php.net | Date: | Mon, 08 Jul 2013 19:49:27 +0000 |
| Subject: | note 86971 deleted from book.array by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195509@lists.php.net to get a copy of this message | ||
Note Submitter: jorge at andrade dot cl
----
To calculate the average of a array
<?php
function array_avg($array,$precision="2"){
$a=0;
if(is_array($array)){
foreach($array as $value):
if(!is_numeric($value)){
$a++;
}
endforeach;
if($a==0){
$cuantos=count($array);
return round(array_sum($array)/$cuantos,$precision);
}else{
return "ERROR in function array_avg(): the array contains one or more non-numeric
values";
}
}else{
return "ERROR in function array_avg(): this is a not array";
}
}
?>