# 4+9=49?

## Recommended Posts

Lets say I have two variables:

`\$var1 = 4;\$var2 = 9;`

`\$var1+\$var2=\$var3;`

And output them:

`echo \$var2;`

I get 49.......How would I make it actually adds the values (=13)?

##### Share on other sites

<?php\$var1 = 4;\$var2 = 9;\$var1+\$var2=\$var3; // \$var2 = \$var3 --> \$var1 + \$var3 --> logic wrongecho \$var1; echo \$var2;//no valueecho \$var3;//no value\$var1 = 4;\$var2 = 9; \$var3=\$var1+\$var2;echo \$var3; // value is 13

##### Share on other sites

What liuyang was showing is that you have the order wrong. The equals (assigment) operator is a right-to-left operator. So, everything on the right side of the operator gets evaluated, and stored to whatever is on the left side. So, with this statement:\$var = 1 + 2 + (3 * 4 * (5 / 6) * 7) + 8;Everything on the right side of the equals (the equation) gets evaluated first, and then assigned to what is on the left side of the equals (the variable). So, if you want to add \$var1 and \$var2 and store the result in \$var3, it is written like this:\$var3 = \$var1 + \$var2;