note 75049 deleted from function.array-product by levim
| From: | levim@php.net | Date: | Tue, 18 Mar 2014 19:46:21 +0000 |
| Subject: | note 75049 deleted from function.array-product by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198974@lists.php.net to get a copy of this message | ||
Note Submitter: gmail at algofoogle
----
Just in relation to "bishop" and the overall behaviour of array_product... The "empty
product" (i.e. product of no values) is supposed to be defined as "1":
http://en.wikipedia.org/wiki/Empty_product
...however PHP's array_product() returns int(0) if it is given an empty array. bishop's
code does this, too (so it IS a compatible replacement). Ideally, array_product() should probably
return int(1). I guess it depends on your specific context or rationale.
You might normally presume int(0) to be a suitable return value if there are no inputs, but
let's say that you're calculating a price based on "percentage" offsets:
$price = 10.0;
$discounts = get_array_of_customer_discounts();
$price = $price * array_product($discounts);
...if there are NO "discounts", the price will come out as 0, instead of 10.0