Logical and Relational Operators

Relational operators compare values and return either TRUE or FALSE. Logical operators perform logical operations on TRUE and FALSE. Values used with a logical operator are converted into booleans prior to being evaluated. For numerical values, zero will be interpreted as FALSE, and other values will be TRUE. Empty strings are considered be FALSE, and any nonempty string is TRUE. Table 2.5 lists the logical and relational operators.

Table 2.5. Logical and Relational Operators
OperatorOperation Performed
<Is Less Than
>Is Greater Than
<=Is Less Than or Equal To
>=Is Greater Than or Equal To
==Is Equal To
!=Is Not Equal To
AND &&And
OR ||Or
XORExclusive Or
!Not

Notice that the equality operator is very similar to the assignment ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.