note 75049 added to function.array-product
| From: | gmailatalgofoogle at osu1 dot php dot net | Date: | Thu, 10 May 2007 04:18:26 +0000 |
| Subject: | note 75049 added to function.array-product | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126375@lists.php.net to get a copy of this message | ||
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
----
Server IP: 203.220.0.234
Probable Submitter: 203.122.246.187 (proxied: 1.1 PROXY)
----
Manual Page -- http://www.php.net/manual/en/function.array-product.php
Edit -- https://master.php.net/note/edit/75049
Del: integrated -- https://master.php.net/note/delete/75049/integrated
Del: useless -- https://master.php.net/note/delete/75049/useless
Del: bad code -- https://master.php.net/note/delete/75049/bad+code
Del: spam -- https://master.php.net/note/delete/75049/spam
Del: non-english -- https://master.php.net/note/delete/75049/non-english
Del: in docs -- https://master.php.net/note/delete/75049/in+docs
Del: other reasons-- https://master.php.net/note/delete/75049
Reject -- https://master.php.net/note/reject/75049
Search -- https://master.php.net/manage/user-notes.php