-
adding an array together
I want to add the array that is an input. so it would add like this
resistor[1] + resistor[2] + ... and so on. But it won't add all of them for some reason.
if I have 2 inputs of 1000 it only shows 1000 instead of 2000.
PHP Code:
$r = $resistors[1] + $resistors[2] + $resistors[3] + $resistors[4]
+ $resistors[5] + $resistors[6] + $resistors[7] + $resistors[8];
how do I get it so if there was only 2 input it would add then instead of adding all of them all the time. I tried the for loop but I don't think I did it right.
-
doh!! :D I didn't start with 0, so it is adding right (now), I still want to know how to put it in a loop and add them on how many there are in the inputs
-
are we talking PERL here?
if so...
PHP Code:
$total = 0;
foreach $element (@resistor)
{
total += $element;
}
print "$total";
It's been a while, but I think that works.
:)
-
nope sorry john my man, php all the way. I should have said something at the beginning, must have been asleep on the toilet on this one. :D:D
-