downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Voting

Please answer this simple SPAM challenge: max(zero, eight)?
(Example: nine)

The Note You're Voting On

gmail at algofoogle
6 years ago
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

<< Back to user notes page

 
show source | credits | stats | sitemap | contact | advertising | mirror sites