|
Current Topic: View Topic Tree |
Everything > Science & Technology > Computers > Programming > PHP |
|---|
|
|
== |
|
|
:: |
|
|
= |
|
|
# |
|
|
<> |
In the PHP programming language, == is the symbol that is used to check for equality between two values, same as in the languages C and C++.
It is very easy to forget that the assignment operator = cannot be used to check for equality. For example, consider the following code:
1. $x = 0;
2. if ($x = 0) $y = 5;
You might expect that since line #1 just set $x to 0, then the condition in the if statement would evaluate to true and thereby cause $y to be set to 5. But in actuality, the condition in the if statement, $x = 0, merely re-assigns the value 0 to $x and then evaluates the truthfulness of the value returned by that assignment operation, which is 0. In PHP, 0 equates to false in an evaluation of truthfulness, so the expression $y = 5 is never executed.