PHP 8 reference · Array Functions
PHP array_product() Function
Return the product of the values in an array, multiplying them all together. An empty array gives 1.
PHP 8 Since 5.1
Syntax
array_product(array $array): int|float
Parameters
| Parameter | Description |
|---|---|
array |
The input array. |
Return value
The product as an int or float.
Examples
<?php
echo array_product([2, 3, 4]), "\n";
echo array_product([]), "\n";
Output
24 1
<?php
echo array_product(range(1, 5)), "\n"; // 5 factorial
Output
120
Version history
| Version | Change |
|---|---|
| PHP 5.1 | Added |
| PHP 8.3 | Warns about values that can't be multiplied instead of silently skipping them. |
Related
array_sum()· Return the sum of the values in an array. Numeric strings are converted; an empty array gives 0.array_reduce()· Reduce an array to a single value by passing a running total and each element to a callback.- PHP Array Functions · tutorial
- PHP Arrays · tutorial