|
-
Sep 3rd, 2001, 10:36 PM
#1
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.
-
Sep 3rd, 2001, 10:43 PM
#2
doh!! 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
-
Sep 3rd, 2001, 11:37 PM
#3
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.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Sep 4th, 2001, 01:15 AM
#4
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. 
-
Sep 12th, 2001, 09:45 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|