Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

array_product

Multiplies the elements of an array.

Syntax

array_product(array $array): int|float

Parameters

ParameterTypeDescription
$arrayarrayAn array of numbers.

Return value

int|floatThe product of the elements.

Examples

A product and a factorial:

<?php
 
echo array_product([2, 3, 4]), "\n";
echo array_product(range(1, 5));

Output:

24
120

Notes

For an empty array the result is 1.

See also

  • array_sum — Returns the sum of the values in an array.
  • array_reduce — Reduces an array to a single value.

Related recipes

In the tutorial

  • Array functions — Processing arrays in PHP without loops — array_map, array_filter, array_reduce, searching and slicing.

Thanks for reading!

Donate to the site — we work hard for you.