note 96259 deleted from function.array-sum by levim
| From: | levim@php.net | Date: | Tue, 18 Mar 2014 19:40:59 +0000 |
| Subject: | note 96259 deleted from function.array-sum by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198960@lists.php.net to get a copy of this message | ||
Note Submitter: Chris
----
Average array values, ignoring zero values:
<?php
function array_average_nonzero($arr) {
return array_sum($arr) / count(array_filter($arr));
}
?>
<?php
$arr = array(1,2,3,0,0);
echo array_average_nonzero($arr); // returns 2
echo array_sum($arr) / count($arr); // returns 1.2
?>