note 68472 deleted from function.array-sum by levim

From: Date: Tue, 18 Mar 2014 19:40:36 +0000
Subject: note 68472 deleted from function.array-sum by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198959@lists.php.net to get a copy of this message
Note Submitter: Tobias Schlemmer ---- <?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 ) */ ?>

« previous php.notes (#198959) next »