Php double exclamation operator (!!) or double not operator

The right ! will result in a boolean, regardless of the operand. Then the left ! will be applied to that boolean. It means if $row has a truthy value, it will return true, otherwise false, converting to a boolean value.
It is equalent of casting to boolean as it convert anything to boolean.

return (bool)$row;

Another more human, maybe simpler, way to ‘read’ the not not:
The first ‘!’ does 2 things: ‘convert’ the value to boolean, then output its opposite. So it will give true if the value is a ‘falsy’ one.
The second ‘!’ is just to output the opposite of the first.

Leave a Reply