Connecting Tech Pros Worldwide Help | Site Map

Array sum

  #1  
Old July 17th, 2005, 02:37 AM
zoidberg
Guest
 
Posts: n/a
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
  #2  
Old July 17th, 2005, 02:37 AM
Robert Downes
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
function for Calculating sum of values in row and coloms of html table by javascript tarunkhatri answers 17 September 18th, 2009 06:44 AM
hello everyone...addition of bytes which s declared as array in private of class susheela s answers 2 September 9th, 2009 08:45 AM
SUM of array Maximus answers 1 December 27th, 2005 09:55 AM
Array sum dr. zoidberg answers 1 July 17th, 2005 04:31 AM