Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: subtracting from a number untill its equal to another number..

1. ## subtracting from a number untill its equal to another number..

hey..
hmm ok as the title says.. ive searched on the net for any code on this.
i know i need to use a forloop but im unsure how, i never liked loops lol.
i have a val you lets call \$val1 and another \$val2 and \$val3
and i need to do some kinda lop so that it keeps subtracting.. hmm lets say 50 from val1 untill it is equal to or less than \$val2and once it is it gives you the final result as \$val3.
any ideas?
thanks
P

• PHP Code:
```    \$var1 = X;    \$var2 = Y;    \$var3 = \$var1;    while(\$var3 > \$var2)         \$var3 -=50;    echo "var1 \$var1<br>var2 \$var2 <br>var3 \$var3";  ```

• hey.
Thanks -
i put that r ight into a php file an dadded the <? ?> but i get a error on line 4.. any ideas?

• Originally posted by sir pannels
hey.
Thanks -
i put that r ight into a php file an dadded the <? ?> but i get a error on line 4.. any ideas?
try changing:
\$var1 = X and \$var2=Y to numbers, like \$var1 = 1234 and \$var2 = 12

• i already tried that.... thats what i thought first off but it didnt make a defference.
should this work on all versions of php?

• this works fine for me.

PHP Code:
``` <?php    \$var1 = 251;    \$var2 = 49;    \$var3 = \$var1;    while(\$var3 > \$var2)         \$var3 -=50;    echo "var1 \$var1<br>var2 \$var2 <br>var3 \$var3"; ?> ```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•