null(空值):PHP中一种特殊的数据类型,表示空值,即表示没有为该变量设置任何值null(空值)不区分大小写,null和NULL是一样的。
被赋空值可能有三种情况:没有赋什么值、被赋空值null、被unset()函数处理过的变量(出处:《PHP从入门到精通》P47。

实例如下
<?php
    echo  "变量($string1)直接赋值为null";
    $string=null;                                          //$string1被赋空值
    $string3="str";                                      //$string3被赋值str
    if(is_null($strig1=null)){                    //判断$string1是否为空
        echo 'string=null';
    }
    echo '<p>';
    echo '变量($string2)没有被赋值';
    if(is_null($string2=null)){                 //判断$string1是否为空
        echo 'string=null';
    }
    echo '<p>';
    echo '被unset()释放过的变量($string3):';
    unset($string3);
    if(is_null($string3=null)){//判断$string1是否为空
        echo 'string=null';
    }
?>

浏览器处理结果:
变量($string1)直接赋值为nullstring=null
变量($string2)没有被赋值string=null
被unset()释放过的变量($string3):string=null

相关文章:

  • 2021-08-02
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-09-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案