Logical and Relational Operators PHP

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 onverted 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. lists the logical and relational operators.

Logical and Relational Operators

Logical and Relational Operators

Notice that the equality operator is very similar to the assignment operator. That's reasonable. One performs the action of making both sides equal; the right-side value is copied to the variable on the left side. The other asks the question, "Are both sides equal?" The inherent danger is that the two can be confused, and it is difficult to discover. PHP will allow you to put an assignment inside the parentheses of an if statement. If you have an if statement that always seems to evaluate one way, check to make sure you haven't typed = when you meant ==.

If you are unfamiliar with logical operations, refer to. The first two columns enumerate all the possible combined values of p and q, which stand for relational expressions. The other four columns show the results of performing a logical operation on p and q.

Truth table for logical operators

You might have noticed in two versions of the logical operators. For instance, there is both and AND. Operationally, they are the same, but they differ in precedence—a topic discussed at the end of this chapter. Aside from precedence, you are free to use them interchangeably.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics