CKTIS / PHP
array_product()
Multipliziert Arraywerte zu einem Gesamtfaktor.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_product(array $array): int|floatMultipliziert Arraywerte zu einem Gesamtfaktor. Ein leeres Array ergibt 1. Ein Nullfaktor ergibt null, wenn vorher weder Unendlich noch NAN entstanden ist. Nach Gleitkommaüberlauf ergibt Unendlich mal null NAN. Ein großes Ganzzahlprodukt kann in float übergehen und Genauigkeit verlieren. Seit PHP 8.3 löst ein Element, das sich weder in int noch in float umwandeln lässt, E_WARNING aus.
Signatur
array_product(array $array): int|float
Ausgabe des Beispiels
[30,1,0,true]
Beispiele
<?php
echo json_encode([array_product([2,3,5]), array_product([]), array_product([3,0,7]), is_nan(array_product([1e308,1e308,0]))]);
Ergebnis
[30,1,0,true]