php中的null、empty、与“”

来源:互联网 发布:php中输入html 编辑:程序博客网 时间:2024/05/22 09:43

null

The special NULL value represents a variable with no value. NULL is the only possible value of type NULL.

//特殊的NULL值给出一个没有值的变量。NULL是NULL类型的唯一可能值。

A variable is considered to be null if:

//一个变量如果在下列情况被认为是NULL:

    it has been assigned the constant NULL.

    //它被指定为NULL常量。

    it has not been set to any value yet.

    //它还没有被赋予任何值。

    it has been unset().

    //它被销毁了。

empty

bool empty ( mixed $var )

判断是否一个变量被认为是空的。返回布尔值.

它是一个函数。

empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

它仅检查变量,其它任何表达做为$var值都会解析错误。换句话说,这种表达式不会起作用,如:empty(trim($name))

empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.

它给出与$var值相反的boole(是或否)类型的值,仅当$var没有被设置的时候,它才不给提示。

Return Values//返回值 

Returns FALSE if var has a non-empty and non-zero value.

//返回FALSE,如果$var是一个非空或非0值;

The following things are considered to be empty:

//下列情形即被认为empty成立:

    " " (an empty string)

   // " "空字符串;

    0 (0 as an integer)

   // 整数0;

    0.0 (0 as a float)

   // 浮点型0;

    "0" (0 as a string)

    //字符串0;

    NULL

   // null值;

    FALSE

   // false值;

    array() (an empty array)

    //空数组;

    var $var; (a variable declared, but without a value in a class)

    //在一个类中,变量被声明了,但是并没有一个值;

综上,在php看来,上述情况都被empty函数判定为true,包括null;

但事实上,null多表示什么都没有,没对象,没变量,没值;而如果给变量一个" "值,则代表变量已经是一个字符串,只是没有具体值。所以php中empty的外延相当大。数字0也被判定empty;