Double not (!!) operator in PHP

后端 未结 6 1278
广开言路
广开言路 2020-11-29 17:47

What does the double not operator do in PHP?

For example:

return !! $row;

What would the code above do?

6条回答
  •  长情又很酷
    2020-11-29 18:24

    "not not" is a convenient way in many languages for understanding what truth value the language assigns to the result of any expression. For example, in Python:

    >>> not not []
    False
    >>> not not [False]
    True
    

    It can be convenient in places where you want to reduce a complex value down to something like "is there a value at all?".

提交回复
热议问题