array_product
PHP function
Edit on GitHub ✎
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
Calculate the product of values in an array
Description
array_product(array $array): int|float
array_product() returns the product of values in an array.
Parameters
arrayThe array.
Return Values
Returns the product as an integer or float.
Changelog
| Version | Description |
|---|---|
| 8.3.0 | Now emits E_WARNING when array values cannot be converted to Integer or Float. Previously Arrays and Objects where ignored whilst every other value was cast to Integer. Moreover, objects that define a numeric cast (e.g. GMP) are now cast instead of ignored. |
Examples
array_product() examples
php
<?php
$a = array(2, 4, 6, 8);
echo "product(a) = " . array_product($a) . "\n";
echo "product(array()) = " . array_product(array()) . "\n";
?>The above example will output:
output
product(a) = 384
product(array()) = 1