dongni9825
2012-03-14 19:49
浏览 23
已采纳

PHP null var存在[重复]

Possible Duplicate:
Check if value isset and null

If I have $v = NULL; how can I check that $v is exists and it's NULL?

isset($v) => false //because of NULL, but $v exists

图片转代码服务由CSDN问答提供 功能建议

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dsadsadsa1231 2012-03-14 19:52
    已采纳

    You can’t, null is equivalent to a non-existing variable:

    A variable is considered to be null if:

    • it has been assigned the constant NULL.
    • it has not been set to any value yet.
    • it has been unset().

    Only for arrays you can check whether a key exists although its value is null using array_key_exists.

    已采纳该答案
    打赏 评论
  • douniuta4783 2012-03-14 19:51
    打赏 评论
  • drgbpq5930 2012-03-14 19:52

    If you would like to put it all together to test existence and a null value

    <?php
    if(!is_null($v)){
    // do something
    }
    ?>
    
    打赏 评论
  • douping1825 2012-03-14 19:53

    You should be careful using isset on variables that can be null. It's a good way to set yourself up for bugs and problems in the future.

    What you could do for now is to use is_null as an additional test.

    打赏 评论

相关推荐 更多相似问题