Meaning of the operator? [duplicate]

Posted on

Question :

What is the function of by a !! in an if for example? I know that ! by itself reverses the value of a boolean result, but I tested !! and nothing changed in the result, eg:

$teste = true;
if(!!$teste) {
   echo "é verdade!";
} else {
   echo "é mentira!";
}

and resulted in true that if

    

Answer :

The ! operator negates. If I put another ! before, I’ll be denying the first negation.

That is:

If i == verdade and !i == falsa , then !!i == verdade

I could have more denial operators before.

That is, I could have this:

$teste = true;
if(!!!!$teste) {
    echo "é verdade!";
} else {
    echo "é mentira!";
}

… that works fine. I would be denying a denial.

    

Leave a Reply

Your email address will not be published. Required fields are marked *