SUM of array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maximus

    SUM of array

    I want to get the sum of the array key values.

    ex: $key1=>10, $key2=>15, $key3=>5

    I want variable $sum = 30.


    any solution?

  • Janwillem Borleffs

    #2
    Re: SUM of array

    Maximus wrote:[color=blue]
    > I want to get the sum of the array key values.
    >
    > ex: $key1=>10, $key2=>15, $key3=>5
    >
    > I want variable $sum = 30.
    >[/color]

    Kimmo already supplied the solution; with associative arrays, use it with
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    $array = array('key1'=10 , 'key2'=15, 'key3'=5);
    $sum = array_sum(array _values($array) );


    JW


    Comment

    Working...