note 50993 added to function.array-sum
| From: | punchto at hotmail dot com | Date: | Wed, 16 Mar 2005 03:06:55 +0000 |
| Subject: | note 50993 added to function.array-sum | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86524@lists.php.net to get a copy of this message | ||
Microsoft Excel - SUMIF()
function sumif($array,$criteria,$sum_array){
if(is_array($array) && is_array($sum_array) && trim($criteria)!= ""){
$array_count = (count($array) < count($sum_array)) ? count($array):count($sum_array);
for($i=0;$i<$array_count;$i++){
if(ereg("^<",$criteria)){
$value = ereg_replace("^<","",$criteria);
$result += $array[$i] < $value ? $sum_array[$i]:0;
}
elseif(ereg("^>",$criteria)){
$value = ereg_replace("^>","",$criteria);
$result += $array[$i] > $value ? $sum_array[$i]:0;
}
else{
$value = $criteria;
$result += $array[$i] == $value ? $sum_array[$i]:0;
}
}
return $result ? $result:0;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.array-sum.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50993
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50993&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50993&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50993&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50993&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50993&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50993&report=yes
Search -- http://master.php.net/manage/user-notes.php