PYTHON array_product

is this article helpful?
|
Python replacement for PHP's array_product [ edit | history ]
def array_product(lst):
    if not lst:
        return 0 # in PHP, the empty array product is 0; mathematically the correct result would be 1
    else:
        reduce(lambda a,b: a*b, lst)

PHP array_product

PHP original manual for array_product [ show | php.net ]

array_product

(PHP 5 >= 5.1.0)

array_productCalculate the product of values in an array

Description

number array_product ( array $array )

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

Parameters

array

The array.

Return Values

Returns the product as an integer or float.

Examples

Example #1 array_product() examples

<?php

$a 
= array(2468);
echo 
"product(a) = " array_product($a) . "\n";

?>

The above example will output:

product(a) = 384