When I echo !!! 0 it gives me a strange result [closed]

You’re missing that ! is the not operator, and that 0 is a falsy value:

!0;//oposite of "false" ==> true ==> 1
!!!0;//oposite of the oposite of the oposite ==> oposite

When a boolean is echoed, it’s converted to its actual value (if any). For something to be true, it has to be. So true is 1. Likewise, for something to be false, it can’t be, so echo false; shows as an empty string, as deceze pointed out.
To be absolutely clear, you should think of !!!0 as some childish attempt at _”reverse psychology”.

Don't give nothing to me. ~=> Give something to me (Don't + nothing is double negation)
I'm not Not giving nothing to you. ~=> I'm not giving anything (not + not + nothing is tripple negation)

Bottom line, assume n is the number of ! signs preceding a value/var/expression, which we’ll call e:

if n%2 === 0
   (n(!)) e === (boolean)e
if n%2 === 1
   (n(!)) e === !e

IF the number of negation operators preceding the operand is even, the expression will be evaluated to the its value, cast to a boolean value. If the number of negation operators is odd, the expression will be evaluated to its oposite boolean value.
Just replace all !‘s with the oposite of.

Leave a Comment