Exclamation mark in front of variable - clarification needed

╄→尐↘猪︶ㄣ 提交于 2019-11-30 09:07:45

if(! $a) is the same as if($a == false). Also, one should take into account that type conversion takes place when using == operator.
For more details, have a look into "Loose comparisons with ==" section here. From there it follows, that for strings "0" and "" are equal to FALSE ( "0"==false is TRUE and ""==false is TRUE, too).

Regarding posted examples:
Example 1
It will work, but you should note, that both "0" and "" are 'empty' strings.

Example 2
It will work

The ! negates. true becomes false, and anything that evaluated to false becomes true.

If you're writing PHP and you don't know all the operators by heart.. you should not write a single line of code until you know them by heart:

http://php.net/manual/en/language.operators.php

These are absolute basics.

It's a boolean tester. Empty or false.

It's the not boolean operator, see the PHP manual for further detail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!