PHP 8 reference · Array Functions

PHP array_product() Function

Return the product of the values in an array, multiplying them all together. An empty array gives 1.

PHP 8 Since 5.1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array_product(array $array): int|float

Parameters

ParameterDescription
array The input array.

Return value

The product as an int or float.

Examples

Multiply valuesTry it yourself
<?php
echo array_product([2, 3, 4]), "\n";
echo array_product([]), "\n";

Output

24
1
FactorialTry it yourself
<?php
echo array_product(range(1, 5)), "\n"; // 5 factorial

Output

120

Version history

VersionChange
PHP 5.1Added
PHP 8.3Warns about values that can't be multiplied instead of silently skipping them.

Was this page helpful?