By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

Array sum

P: 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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
zoidberg wrote:
How can I Sum numbers from this array to get 8 as result of this array.


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"
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.