Summary: in this tutorial, you will learn how to use the PHP NOT operator (!) to build complex logical expressions.
Introduction to the PHP NOT operator
In other words, the logical NOT operator returns
true if the operand is
false and returns
false if the operand is
PHP uses the both
not keyword and (
!) to represent the logical NOT operator.
The following table illustrates the result of the logical NOT operator:
The logical NOT operator is also known as the logical negation operator.
PHP NOT operator examples
The following example illustrates how to use the logical not operator (
Code language: HTML, XML (xml)
5; var_dump( ! $priority < 5 ); $priority =
In this example, PHP evaluate the expression
! $priority < 5 in the following order:
$priority < 5evaluates to
! falseevaluates to
- PHP NOT operator (
!) accepts an operand and negate the result of the operand.