maintainable / php-ruby-reference
- Source
- Commits
- Network (8)
- Graphs
-
Tree:
16d1dc5
Troels (author)
Sun Jul 12 04:50:47 -0700 2009
php-ruby-reference / array / array_product.markdown
array_product
We can get the product of an array of integers using a combination of Ruby's
Enumerable#inject method with Fixnum#*.
{{code:php
$numbers = array(2, 2, 2, 2);
$result = array_product($numbers);
print $result;
// => 16
}}
{{code:ruby
result = [2, 2, 2, 2].inject {|product, element| product * element }
puts result
# => 16
}}
{{related:
array/array_sum
}}
