Computer >> Computer tutorials >  >> Programming >> PHP

array_product() function in PHP


The array_product() function calculates the product of the values in an array. It returns the product of values.

Syntax

array_product(arr)

Parameters

  • arr − The specified array.

Return

The array_product() function returns the product of values in the array. The value is returned as integer or float.

Example

The following is an example −

<?php
   $arr = array(4,2,9);
   echo(array_product($arr));
?>

Output

The following is the output −

72

Let us see another example wherein we have a mix of integer and float elements in the array. The resultant product will be float −

<?php
   $arr = array(3.5, 9.4,4.3, 5);
   echo(array_product($arr));
?>

Output

707.35