Home >>PHP Array Functions >PHP array_product () Function

PHP array_product () Function

PHP array_product () Function

PHP array_product () Function : The most basic way to calculate the product of all the elements in an array is to iterate over all the elements and calculate the products but PHP delivers its programmers with a built-in function to do this.

The array_product() in PHP is basically a built-in function in PHP and is used in order to find the products of all the elements in an array. The array_product() function generally calculates and returns the product of an array.

Syntax:

array_product(array)

Parameter Values

Parameter Description
array This is generally used to specify an array in the code, it is a mandatory parameter.

Here, is an example of array_product() Function in PHP:


 
Output:
<html>
<body>
<?php
$arg=array(12,7);
echo(array_product($arg));
?>
</body>
</html>
Output:84

Example 2:

<html>
<body>
<?php 
$odd=array(3,5);  
print_r($odd);  
print_r(array_product($odd));  
echo "\n";  
$even=array(6,9);  
print_r($even);  
print_r(array_product($even)); 
?>  
</body>
</html>
Output:
Array ( 
	[0] => 3 
	[1] => 5
 	)
 15
 Array (
 	[0] => 6 
	[1] => 9
 	)
 54

No Sidebar ads