You use a single = to assign a value to a variable, as in
$x = 3;
You use double == to compare two values, to see if they are equal, as in
$x == 3 will be true
$x == 4 will be false
So by using a single = in an if() statement like so
if ($x = 4) {...}
means you assign the value 4 to $x, regardless of it's previous value, and if the operation is succesfull (which it always is) it will return true and the if() statement will always run.
There is also a third operator with three ===, which takes variable types into account when comparing. This should show the difference.
PHP Code:
$x = 3; // the number 3 $y = '3'; // the string '3'
if ($x == $y) { // this is true } if ($x === $y) { // this is false }
__________________
596f75206d65616e20796f752063616e2061637475616c6c79 207265616420746869733f
|