php学习笔记(十二)NULL

来源:互联网 发布:手机淘宝出售二手宝贝 编辑:程序博客网 时间:2024/05/01 18:05

PHP NULL 值

特殊的 NULL 值表示变量无值。NULL 是数据类型 NULL 唯一可能的值。

NULL 值标示变量是否为空。也用于区分空字符串与空值数据库。

可以通过把值设置为 NULL,将变量清空:

<?php$x="Hello world!";$x=null;var_dump($x);?>

输出结果:

NULL


在下列情况下一个变量被认为是 NULL

  • 被赋值为 NULL

  • 尚未被赋值。

  • unset()

转换到 NULL

使用 (unset) $var 将一个变量转换为 null不会删除该变量或 unset 其值。仅是返回NULL 值而已。


//empty array is converted to null by non-strict equal '==' comparison. Use is_null() or '===' if there is possible of getting empty array. $a = array(); $a == null  <== return true $a === null < == return false is_null($a) <== return false 

//empty() is_null() !isset() $var = ""; empty($var) //is true. is_null($var)// is false. !isset($var)// is false. 


0 0
原创粉丝点击