The “NOT NOT” operator or Double not(!!) operator in PHP simply returns the truth value of the variable or expression. To explain in very simple terms, the first not operator(!) negates the expression. The second not operator(!) again negates the expression resulting the true value which was present before.
The (!!) operator returns as that Boolean function. If use !! to an expression the true value will be true and false value would be false. That is no change in the Boolean value. By using this double not(!!) operator it can increase the code readability and also ensure the truth and false values to be strictly Boolean data types.
Difference between logical NOT(!) operator and Double NOT(!!) operator in PHP: The Not operator is the mathematically complements or negates the Boolean value of the concerned data. For example a Boolean value of $a = True, then the NOT operator imposed on it !$a would be False. This is about logical NOT or Negation operator. Where as the Double NOT (!!) operator returns only the Boolean cast or the truth value. That is !!$a is always TRUE.
Here is an another example based on double NOT operator.
The above code strictly save the Boolean data type and returns the truth value of the variable.
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Ternary operator vs Null coalescing operator in PHP
- Bitwise NOT operator in Golang
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
- What does $$ (dollar dollar or double dollar) means in PHP ?
- What is the difference between single-quoted and double-quoted strings in PHP?
- PHP 7 | Spaceship Operator
- PHP | $ vs $$ operator
- 'AND' vs '&&' as operator in PHP
- What is the difference between the | and || or operator in php?
- PHP | Ternary Operator
- Scope Resolution operator in PHP
- Double Brace Initialization in Java
- Modulus of two float or double numbers
- Double Layered Text Effect using CSS
- Convert String to Double in Java
- Convert Double to Integer in Java
- What is the use of a double-click event in AngularJs?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.