Im trying to test a validation using an if statement.
if (($red == "1") && ($blue = "1") ) { $green = "hello"; }
Before this statement runs $blue = 0.
After i run this... $blue changes to 1.
Any ideas why?
You are using = in place of ==:
if (($red == "1") && ($blue = "1") ) { $green = "hello"; }
^^^
As a result (assuming the left side of && returns true) $blue gets assigned "1".
It's one of the most common programming mistakes!! As a way to prevent it from happening programmers put the constant on the left hand side of the the == as:
1 == $blue
so that if by mistake you end up writing = in place of == :
1 = $blue
you get a syntax error as you cannot assign to a constant.
$red == "1"but not for$blue?