PHP to Ruby
Convert PHP code into Ruby!
-
array_product
Posted on February 17th, 2010 No commentsThe array_product() PHP function returns the product of all values in an array. In other words, it multiplies all values in the array together, and returns the result as a number.
PHP
$a = array('1', '2', '3'); $product_total = array_product($a); echo $product_total; // => 6
Ruby
a = [ "1", "2", "3" ]; product_total = a.inject {|product, element| product * element } puts product_total; # => 6
Leave a reply


