Logical Operators AND and OR
suggest changeIn PHP, there are two versions of logical AND and OR operators.
Operator | True if ———– | ––––––– $a and $b
| Both $a
and $b
are true $a && $b
| Both $a
and $b
are true $a or $b
| Either $a
or $b
is true $a || $b | Either `$aor
$b` is true
Note that the &&
and ||
opererators have higher precedence than and
and or
. See table below:
Evaluation | Result of $e
| Evaluated as ——————— | ——————— | ———— $e = false || true | True | $e = (false || true) `$e = false or true| False |
($e = false) or true`
Because of this it’s safer to use &&
and ||
instead of and
and or
.
Found a mistake? Have a question or improvement idea?
Let me know.
Logical Operators AND and OR
Table Of Contents
3 Arrays
5 Types
10 Sessions
11 Cookies
15 JSON
16 SOAP
17 Reflection
18 cURL
20 XML
22 Traits
23 Namespaces
24 Parsing HTML
30 Type hinting
33 Generators
34 Operators
35 Constants
36 UTF-8
37 URLs
39 PHPDoc
42 Loops
45 Closur
48 Security
49 PHP MySQLi
51 Localization
52 Debugging
54 Unit testing
56 References
61 Performance
68 Using SQLSRV
70 Functions
73 YAML
76 SOAP Server
78 Cache
79 Streams
81 Cryptography
82 PDO
83 SQLite3
84 Sockets
88 MongoDB
93 Comments
94 IMAP
95 Redis
96 Imagick
97 SimplXML
99 Recipies
102 WebSockets
103 APCu
104 Design patterns
106 PHP mysqli
109 PSR
110 Contributors