Logical Operators and Compound Conditions
Great job! You’ve learned the tools needed to craft programs with powerful decision making capabilities. Let’s review what we covered:
- By nesting conditionals within one another, we can create branching decisions.
- The logical operator
||takes two different boolean values or expressions as its operands and returns a single boolean value. It returns
TRUEif either its left operand or its right operand evaluate to
- The logical
TRUEonly if both of its operands evaluate to
TRUE. It returns
FALSEif either or both of its operands evaluate to
- The logical not operator (
!) takes only a right operand. It reverses the boolean value of its operand.
- The logical exclusive or operator (
TRUEonly if either its left operand or its right operand evaluate to
TRUE, but not both or neither.
- PHP includes alternate syntax for the
&&operators: we can use
orin place of
||, and we can use
andin place of
&&. These operators work much the same way but have different operator precedence.
- We can include code from one file inside another with
includewhich allows us to write mode modular programs.