Jump to content

4+9=49?


kewley

Recommended Posts

<?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

Link to comment
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;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...