Calculate the product of all values in an array.
The array_product() function returns the product of all values in an array. It multiplies all the values together, starting from 1. For an empty array, it returns 1 (the multiplicative identity).
Like array_sum(), it handles both integer and float values. Non-numeric values are converted to their numeric equivalents following PHP's type juggling rules.
Useful for calculating factorials, compound interest, combined probabilities, and any scenario requiring multiplication of a series of values.
| Name | Description | Optional |
|---|---|---|
array |
The array of values to multiply. | No |
echo array_product([1, 2, 3, 4]); // 24
echo array_product([2, 5, 10]); // 100
echo array_product([]); // 1