note 71463 deleted from function.array-product by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:59:47 +0000 |
| Subject: | note 71463 deleted from function.array-product by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197283@lists.php.net to get a copy of this message | ||
Note Submitter: bishop
----
Yet another implementation of array_product() using PHP's native array_reduce():
if (! function_exists('array_product')) {
function array_product($array) {
if (is_array($array)) {
return (0 == count($array) ? 0 : array_reduce($array, '_array_product', 1));
} else {
trigger_error('Param #1 must be an array', E_USER_ERROR);
return false;
}
}
function _array_product($v,$w) { return $v * $w; }
}