Loading video...
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.
- Additional Resources:
Logical & Ternary Operators
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.



































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview