null(空值):php中一种特殊的数据类型,表示空值,即表示没有为该变量设置任何值null(空值)不区分大小写,null和null是一样的。
被赋空值可能有三种情况:没有赋什么值、被赋空值null、被unset()函数处理过的变量(出处:《php从入门到精通》p47。
实例如下:
echo "变量($string1)直接赋值为null";
$string=null; //$string1被赋空值
$string3="str"; //$string3被赋值str
if(is_null($strig1=null)){ //判断$string1是否为空
echo 'string=null';
}
echo '
';
echo '变量($string2)没有被赋值';
if(is_null($string2=null)){ //判断$string1是否为空
echo 'string=null';
}
echo '
';
echo '被unset()释放过的变量($string3):';
unset($string3);
if(is_null($string3=null)){//判断$string1是否为空
echo 'string=null';
}
?>
浏览器处理结果:
变量($string1)直接赋值为nullstring=null
变量($string2)没有被赋值string=null
被unset()释放过的变量($string3):string=null
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号