Friday, June 12, 2026
HomeLanguagesDouble not (!!) operator in PHP

Double not (!!) operator in PHP

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.

Example 1:




<?php
  
// Declare a variable 
// and initialize it
$a = 1;
  
// Use double not operator
$a = !!$a;
  
// Display the value 
// of variable a.
echo $a;
?>


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.

Example 2:




<?php
  
// PHP program to illustrate
// Double NOT operator
  
// Declare a variable and 
// initialize it
$t = 10;
  
// Check condition
if ($t !== 10)
    echo "This is NOT operator!";
elseif (!!$t)
    echo "This is Double NOT operator!";
else
    echo "Finish!";
?>


The above code strictly save the Boolean data type and returns the truth value of the variable.

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS