How to multiply the values of an array

Discussion in 'PHP' started by Ipodman79, Feb 6, 2014.

  1. #1
    How do I multiply the values of an array?

    So

    
    $x = array(1, 2, 3, 4, 5);
    
    PHP:
    I want to multiply them as quick and as easy as possible so I get the answer 120?

    Thanks.
     
    Ipodman79, Feb 6, 2014 IP
  2. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #2
    Use "array_product" Like this:
    <?php
    $x = array(1, 2, 3, 4, 5);
    echo  array_product($x);
    ?>
    Code (markup):
     
    malky66, Feb 6, 2014 IP
    ryan_uk likes this.