Connecting Tech Pros Worldwide Help | Site Map

Array sum

zoidberg
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Guest
 
Posts: n/a
#2: Jul 17 '05

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 fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk"
Closed Thread