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 : 

$t = 5; 

if ($t !== 5) 

    echo "This is NOT operator!"; 

elseif (!!$t) 

    echo "This is Double NOT operator!"; 

else

    echo "Finish!"; 

?> 


Php Related Topic's