null和empty有什么区别? [英] What is the difference between null and empty?
问题描述
我对空和空的概念是陌生的.尽管我尽力了解它们之间的区别,但我更加困惑.我在 http://www.tutorialarena.com/blog/php-isset-上遇到了一篇文章vs-empty.php ,但是我仍然看不到在验证表单时何时使用isset和empty.看到我不明白它们之间的区别,我不想使用不正确的功能,也不想在其他领域使用这些功能.有人可以举一些例子来帮助我理解吗?我对编码非常陌生,因此如果有人可以给我提供真实的示例并同时使其足够简单以使noob能够理解,我将不胜感激.
I am new to the concept of empty and null. Whilst I have endeavoured to understand the difference between them, I am more confused. I came across an article at http://www.tutorialarena.com/blog/php-isset-vs-empty.php however I still don't see when you would use isset and empty when validating forms. Seeing that I don't grasp the difference, I don't want to be using the incorrect functions as well as not be able to use the functions in other areas. Can someone give examples that will help me understand? I am very new to coding so would appreciate if someone could give me real world examples and at the same time keep it simply enough for noob to follow.
推荐答案
如果变量没有值,并且指向内存中无处,则该变量为NULL
.
A variable is NULL
if it has no value, and points to nowhere in memory.
empty()
更像是 empty 的字面意思,例如字符串""
为空,但不是 NULL
.
empty()
is more a literal meaning of empty, e.g. the string ""
is empty, but is not NULL
.
以下事项被认为是 为空:
The following things are considered to be empty:
- "(一个空字符串)
- 0(0为整数)
- 0.0(浮点数为0)
- "0"(0作为字符串)
- NULL
- 假
- array()(一个空数组)
- var $ var; (已声明的变量,但在类中没有值)
- "" (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
.
如果
$a=''
为空但不是NULL
,则何时使用empty()
函数以及何时使用isset()
函数.
If
$a=''
is empty but notNULL
, when do I use theempty()
function and when do I use theisset()
function.
isset()
将返回FALSE
是变量所指向的到NULL
.
isset()
will return FALSE
is the variable is pointing to NULL
.
了解什么是空时,请使用empty()
(请参见上面的列表).
Use empty()
when you understand what is empty (look at the list above).
同样,当您说它在内存中没有指向时,那到底是什么意思?
Also when you say it points nowhere in memory, what does that mean exactly?
这意味着$str = ''
将作为长度为0的字符串存储在内存中.
It means that $str = ''
will be in memory as a string with length of 0.
如果是$str = NULL
,则不会占用任何内存.
If it were $str = NULL
, it would not occupy any memory.
这篇关于null和empty有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!