array_product

(PHP 5 >= 5.1.0, PHP 7)
Calculate the product of values in an array
number array_product ( array $array )

array_product() returns the product of values in an array.

Parameters:
array

The array.

Returns:

Returns the product as an integer or float.

Changelog:
5.3.6

The product of an empty array is now 1, when before this function would return 0 for an empty array.

Examples:
array_product() examples
<?php

$a = array(2, 4, 6, 8);
echo "product(a) = " . array_product($a) . "\n";
echo "product(array()) = " . array_product(array()) . "\n";

?>

The above example will output:

product(a) = 384
product(array()) = 1
doc_php
2016-02-24 16:12:48
Comments
Leave a Comment

Please login to continue.