array_product
Multiplies the elements of an array.
Syntax
array_product(array $array): int|floatParameters
| Parameter | Type | Description |
|---|---|---|
| $array | array | An array of numbers. |
Return value
int|floatThe product of the elements.
Examples
A product and a factorial:
<?php
echo array_product([2, 3, 4]), "\n";
echo array_product(range(1, 5));Output:
24
120Notes
For an empty array the result is 1.
See also
- array_sum — Returns the sum of the values in an array.
- array_reduce — Reduces an array to a single value.
Related recipes
In the tutorial
- Array functions — Processing arrays in PHP without loops — array_map, array_filter, array_reduce, searching and slicing.