logical operators or vs || (double pipe) in php -
this question has answer here:
- logical operators, || or or? 7 answers
i've used ||
(double pipe) if (($a == $b) || ($a == $c)) { }
, or
do_this() or do_that();
.
why not if (($a == $b) or ($a == $c)) { }
or do_this() || do_that();
?
is there reason use of these 2 logical operators or personal preference?
the same applies &&
vs and
, use &&
.
the "spelled out" operators and
, or
have lower precedence, lower assignment, may use them avoid having write parentheses in many places. example:
$d=$a||$b , $c
equivalent ($d=$a||$b) && $c
they more readable in many contexts.
Comments
Post a Comment