### Start Learning Now

Our free lessons will get you started (Flash® 10 required).

### Logical & Ternary Operators

• Logical operators are used to create complex boolean expressions and operate on boolean operands. PHP’s logical operators are:
• NOT ( ! ) – unary operator that returns TRUE if its operand is FALSE
• OR ( || , or ) – binary operators that return TRUE if either operands are TRUE
• AND ( && , and ) – binary operators that return TRUE only if both operands are TRUE
• XOR ( xor ) – binary operator that returns TRUE if either operand is TRUE , but not both
• The OR and AND logical operators have two options because the options have different precedence:
• || has a higher precedence than or
• && has a higher precedence than and
• The OR and AND logical operators are known as short-circuit operators meaning that if the value of their left operand can determine the result of the operation, the right operand never gets evaluated.
• The ternary operator is the only ‘ternary’, or three-operand, operator in PHP. If a ternary operator’s 1st operand evaluates to TRUE , then the value of the 2nd operand is the result of the operation, otherwise the value of the 3rd operand is the result of the operation.