ahua671 发表于 2015-8-29 07:15:11

php null空值(转)

  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
页: [1]
查看完整版本: php null空值(转)