473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding up arrays

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
1 1963
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

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

Similar topics

7
by: David | last post by:
I have an array that contains numbers in string elements , i want to convert this to integers, i have made a for loop that uses the number of elements in the array and then adds 0, thereby...
0
by: Björn | last post by:
Hello, Starting to code a robust routine to add two arrays element by element $new = $a + $b ... I thought that this should already be done and searched CPAN for a sutiable module. Despite...
6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
23
by: Rick | last post by:
Hi, This is probably simple byt when you never did pointers and being used to luxery strings like in Delphi or Visual Basic, C can get though. What I'm trying to do is to add chars to a string....
5
by: Troy | last post by:
Hello, I have a dumb question. I have two array objects of type double with 12 elements in each object. I'd like to add the two objects but dont know how to. Any ideas? thanks
6
by: Maheshkumar.R | last post by:
How i can store images in array @ runtime..? What are the possbile ways.. Thankz.. - Mähésh Kumär. R
11
by: dennis.sprengers | last post by:
Consider the following multi-dimensional array: --------------------------- $arr = array( array(3, 5, 7, 9), array(2, 4, 6, 8), array(1, 3, 5, 7) ); function add_arrays($arr) { for ($row =...
6
by: santiago | last post by:
I guess one cannot do this: arraytot = arraytot + arraydet; So, what's the trick to adding arrays like this? Thanks.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.