PHP-检查变量是否未定义 [英] PHP - check if variable is undefined

查看:81
本文介绍了PHP-检查变量是否未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑此jquery语句

Consider this jquery statment

isTouch = document.createTouch !== undefined

我想知道我们是否在PHP中有类似的语句,不是isset(),而是从字面上检查未定义的值,例如:

I would like to know if we have a similar statement in PHP, not being isset() but literally checking for an undefined value, something like:

$isTouch != ""

PHP中是否存在与上述类似的东西?

Is there something similar as the above in PHP?

推荐答案

您可以使用-

$isTouch = isset($variable);

如果定义了$variable,则将存储true,否则将存储false.如果需要反演,只需删除!.

It will store true if $variable is defined else false. If need the invers the simply remove the !.

注意:如果var存在并且具有非NULL的值,则返回TRUE,否则返回FALSE.

Note : Returns TRUE if var exists and has value other than NULL, FALSE otherwise.

或者如果您要检查false0等,请使用empty()-

Or if you want to check for false, 0 etc also then use empty() -

$isTouch = empty($variable);

empty()适用于-

  • " (一个空字符串)
  • 0 (0为整数)
  • 0.0 (浮点数为0)
  • "0" (0为字符串)
  • NULL
  • 错误
  • array() (一个空数组)
  • $ var; (已声明变量,但没有值)
  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • $var; (a variable declared, but without a value)

这篇关于PHP-检查变量是否未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆