(PHP 5 >= 5.1.0, PHP 7, PHP 8)
array_product — Calculate the product of values in an array
array_product() returns the product of values in an array.
array
The array.
Returns the product as an integer or float.
Version | Description |
---|---|
8.3.0 |
Now emits E_WARNING when array values
cannot be converted to int or float.
Previously arrays and objects where ignored whilst every other value was cast to int.
Moreover, objects that define a numeric cast (e.g. GMP) are now cast instead of ignored.
|
Example #1 array_product() examples
<?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:
product(a) = 384 product(array()) = 1