Meaning of the operator? [duplicate]

4

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

    
asked by anonymous 19.01.2016 / 12:19

1 answer

3

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.

    
19.01.2016 / 12:24