note 92939 deleted from language.operators.logical by danbrown
| From: | danbrown@php.net | Date: | Sat, 15 Aug 2009 17:59:40 +0000 |
| Subject: | note 92939 deleted from language.operators.logical by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159516@lists.php.net to get a copy of this message | ||
Note Submitter: ravenswd at gmail dot com
----
People seem to think that || and && are better to use than "or" and
"and" in every situiation. The reality is that it only matters in situations where one is
setting a variable equal to the result of a logical expression, as the previously-posted examples
illustrate. In almost every other use, || and "or" are equivalent:
<?php
if ($filename == '.' || $filename == '..') { continue; }
if ($filename == '.' or $filename == '..') { continue; }
?>
These two lines will produce exactly the same results, but the second line is (in my opinion)
clearer, because it uses an English word rather than an abstract symbol. If one is really worried
about operator precedence, one can always use parenthesis, like this:
<?php
if ( ($filename == '.') or ($filename == '..') ) { continue; }
?>
This version is clearest of all.