Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


The PHP Array array_product() function is used to return the product of all values in the array. Please note that, the function converts string elements of the array into numbers. If a element can not be converted into number, it is converted to 0.

Syntax

array_product(array)

Parameters

array Required. Specify an array.

Return Value

Returns the product of all values in the array.

Exceptions

NA.

Example:

In the below example, array_product() function is used to calculate the product of all values in the given indexed array.

<?php
$MyArray = array(1, 2, 3, 4, 5);
$prod = array_product($MyArray);

echo $prod;
?>

The output of the above code will be:

120

Example:

In the below example, the function is used to calculate the product of all values in the given associative array.

<?php
$MyArray = array("Marry"=>10, "John"=>20, "Jo"=>30);
$prod = array_product($MyArray);

echo $prod;
?>

The output of the above code will be:

6000

❮ PHP Array functions