Array sum

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

    Array sum

    Hello,

    I have an Array that looks like this:

    Array
    (
    [0] => Array
    (
    [0] => Number 1
    [1] => 3
    )

    [1] => Array
    (
    [0] => Number 2
    [1] => 3
    )

    [2] => Array
    (
    [0] => Number 3
    [1] => 2
    )

    )


    How can I Sum numbers from this array to get 8 as result of this array.

    TNX
  • Robert Downes

    #2
    Re: Array sum

    zoidberg wrote:[color=blue]
    > How can I Sum numbers from this array to get 8 as result of this array.[/color]

    You can reference the inner values by using as many indices as the array
    has dimensions. In your case, two dimensions. So to get to the numbers,
    you need to refer to

    $myarray[0][1]
    $myarray[1][1]
    $myarray[2][1]

    Just build a for loop that does this as many times as you need (using
    the count() function to find the size of the first dimension).
    --
    Bob
    London, UK
    echo Mail fefsensmrrjyahe eoceoq\! | tr "jefroq\!" "@obe.uk"

    Comment

    Working...