note 68472 added to function.array-sum
| From: | TobiasSchlemmer at osu1 dot php dot net | Date: | Fri, 28 Jul 2006 06:41:16 +0000 |
| Subject: | note 68472 added to function.array-sum | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115292@lists.php.net to get a copy of this message | ||
<?php
$array1 =
array('1'=>'1','2'=>'2','3'=>'3');
$array2 = array(
'2'=>'1','3'=>'2','4'=>'3');
$array3 = array(
'3'=>'1','4'=>'2','5'=>'3');
$array = array_sum_values( $array1, $array2, $array3 );
print_r($array);
/**
* Sums the values of the arrays be there keys (PHP 4, PHP 5)
* array array_sum_values ( array array1 [, array array2 [, array ...]] )
*/
function array_sum_values() {
$return = array();
$intArgs = func_num_args();
$arrArgs = func_get_args();
if($intArgs < 1) trigger_error('Warning: Wrong parameter count for
array_sum_values()', E_USER_WARNING);
foreach($arrArgs as $arrItem) {
if(!is_array($arrItem)) trigger_error('Warning: Wrong parameter values for
array_sum_values()', E_USER_WARNING);
foreach($arrItem as $k => $v) {
$return[$k] += $v;
}
}
return $return;
}
/* result:
Array
(
[1] => 1
[2] => 3
[3] => 6
[4] => 5
[5] => 3
)
*/
?>
----
Server IP: 217.173.238.131
Probable Submitter: 80.248.198.163 (proxied: 192.168.200.103)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-sum.php
Edit -- http://master.php.net/note/edit/68472
Del: integrated -- http://master.php.net/note/delete/68472/integrated
Del: useless -- http://master.php.net/note/delete/68472/useless
Del: bad code -- http://master.php.net/note/delete/68472/bad+code
Del: spam -- http://master.php.net/note/delete/68472/spam
Del: non-english -- http://master.php.net/note/delete/68472/non-english
Del: in docs -- http://master.php.net/note/delete/68472/in+docs
Del: other reasons-- http://master.php.net/note/delete/68472
Reject -- http://master.php.net/note/reject/68472
Search -- http://master.php.net/manage/user-notes.php