Double not (!!) operator in PHP

后端 未结 6 1280
广开言路
广开言路 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:34

    It's the same (or almost the same - there might be some corner case) as casting to bool. If $row would cast to true, then !! $row is also true.

    But if you want to achieve (bool) $row, you should probably use just that - and not some "interesting" expressions ;)

提交回复
热议问题