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

Adding up arrays

P: 2
I have several 2-dimensional arrays which I want to sum the values of, returning an array that has for each of its values the sum from all the others (if that makes sense?) ... Okay ... maybe an example will make it clearer! ;-)

$array1 = array(array(1,1,1), array(1,1,1), array(1,1,1));
$array2 = array(array(2,2,2), array(0,0,0), array(3,3,3));

... So is there a clever / fast way to add up the values of the two arrays above to return the following array?

$array3 = array(array(3,3,3), array(1,1,1), array(4,4,4));

All I can think of doing at the moment is iterating through the values of each array and add them to a new array... which can get very slow when there are lots of arrays to add up / the arrays are bigger.

Thanks for your help!
Sep 11 '06 #1
Share this Question
Share on Google+
1 Reply

P: 2
Oh no... was my question that difficult? If anybody could even give me steer as to what functions I should look for in the PHP manual, that would help. Thanks!
Sep 12 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.