note 40818 deleted from language.control-structures by aidan
| From: | aidan@php.net | Date: | Thu, 07 Oct 2004 13:51:07 +0000 |
| Subject: | note 40818 deleted from language.control-structures by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78127@lists.php.net to get a copy of this message | ||
Note Submitter: Steve at SJHanna dot com
----
A bit of advice about using == in if statements: Instead of
if ($a == 0 ) ...
write
if (0 == $a) ...
Clearly, the order doesn't matter. However, if you inadventently were to write
if ($a = 0) // Note the assignment!
your test would always return false! That's because you've assigned the value 0 to $a,
then tested that value, and 0 is false. On the other hand, if you wrote
if (0 = $a) ...
the processor will give you an error, since you can't assign a value to a constant.