Logical Operators

This lesson covers logical operators and how we can use them to evaluate conditions in PHP.

What are Logical Operators? #

Logical operators are used to combine conditional statements. This means that the program can take a decision based on multiple conditions. You will learn more about conditional statements later. But for now, suffice it to say, that conditional statements are those that can either be true or false.

Types of Logical Operators #

There are two logical operators:

  • && or and
  • || or or

The And Operator #

The and or && operator returns true if all the statements are true and false if one or more statements are false. Say we have two statements a and b. The following table illustrates this behavior.

a b a&&b or a and b
true true true
true false false
false true false
false false false

Run the code below to see how this works.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy