In this lesson our instructor talks about logical and ternary operators. First, he discusses logical operators and some logical operators coding example. Then he talks about short-circuit operators, ternary operator, and some coding conventions. He ends the lesson with a helpful homework challenge.
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
|| 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.
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.