array_product()
Product is a mathematical term for the result of multiplying. This function will multiply the values of an array and return you the final product.
Non-numeric values will be converted. This means that a string not starting with a digit will evaluate to zero and therefore the product will be zero. For multidimensional arrays, the nested arrays will be ignored. Your result will be an integer or float depending on the array’s values.
$p = array_product( array(4, 6, 2) ); // 48 $p = array_product( array(4, 6, '2') ); // 48 $p = array_product( array(4, 6, '2monkey') ); // 48 $p = array_product( array(4, 6, 'monkey') ); // 0 $p = array_product( array(4.5, 6.92, 2) ); // 62.28 $arr = array(4, 6, array(5, 2)); $p = array_product( $arr ); // 24
Below we use array_product() to calculate the factorial (n!) of $n (assuming it is non-negative by this point).
$p = array_product( $range(1, $n) );
See the manual entry for array_product()
