Created
January 15, 2012 01:16
-
-
Save masakielastic/1613751 to your computer and use it in GitHub Desktop.
Excel の SUMPRODUCT 関数を PHP で定義
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sum_product($array, $array2) { | |
$ret = array_map(function($m, $n) { return $m * $n; }, $array, $array2); | |
// return array_sum($ret); | |
return array_reduce($ret, function($m, $n) { return $m + $n; }, 0); | |
} | |
var_dump(sum_product([100, 200, 300], [1, 2, 3])); // 1400 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment