array_product()
array_product() — Calculate the product of values in an array.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
array_product(array $array): int|float
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $array | array | The array. |
Return value
Returns the product as an integer or float.
Example
A runnable snippet:
$a = array(2, 4, 6, 8); echo "product(a) = " . array_product($a) . "\n"; echo "product(array()) = " . array_product(array()) . "\n";
Output:
product(a) = 384 product(array()) = 1
Changelog
| Version | Change |
|---|---|
| 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. |
All PHP 8.5 built-in functions
Reference card built from the PHP manual page array_product() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.