我是空和null概念的新手.虽然我努力了解它们之间的区别,但我更加困惑.我在http://www.tutorialarena.com/blog/php-isset-vs-empty.php遇到了一篇文章但是我仍然没有看到在验证表单时何时使用isset和empty.看到我没有掌握差异,我不想使用不正确的功能,也不能使用其他区域的功能.有人可以提供一些有助于我理解的例子吗?我对编码很陌生,所以如果有人能给我真实世界的例子,并且同时保持它足以让noob遵循,我将不胜感激.
解决方法:
如果变量没有值,则该变量为NULL,并指向内存中的任何位置.
empty()更像是空的字面意思,例如字符串“”为空,但不是NULL.
The following things are considered to
be empty:
“” (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
“0” (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)
例
$a是NULL.
$a =”为空,但不为NULL.
更新
If $a='' is empty but not NULL, when do I use the empty() function and when do I use the isset() function.
isset()将返回FALSE,变量指向NULL.
当你理解什么是空的时候使用empty()(看看上面的列表).
Also when you say it points nowhere in memory, what does that mean exactly?
这意味着$str =”将在内存中作为长度为0的字符串.
如果它是$str = NULL,它就不会占用任何内存.
标签:isset,php,null
来源: https://codeday.me/bug/20190925/1817587.html