array_product

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

array_productCalculate the product of values in an array

Descrizione

array_product(array $array): int|float

array_product() returns the product of values in an array.

Elenco dei parametri

array

The array.

Valori restituiti

Returns the product as an integer or float.

Log delle modifiche

Versione Descrizione
8.3.0 Now emits E_WARNING when array values cannot be converted to int or float. Previously arrays and objects where ignored whilst every other value was cast to int. Moreover, objects that define a numeric cast (e.g. GMP) are now cast instead of ignored.

Esempi

Example #1 array_product() examples

<?php

$a
= array(2, 4, 6, 8);
echo
"product(a) = " . array_product($a) . "\n";
echo
"product(array()) = " . array_product(array()) . "\n";

?>

Il precedente esempio visualizzerà:

product(a) = 384
product(array()) = 1