判断php变量是否定义,是否为空
2010-05-24 05:04
471 查看
isset() 【1】
Returns TRUE if var
exists and has value other
than NULL, FALSE otherwise.
输入可以是多个变量,只有所有的变量为真的时候,返回真
empty()【2】
Returns FALSE if var
has a non-empty
and non-zero value.
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a
value in a class)
输入只能是一个变量
is_null() 【3】
Returns TRUE if var is
null , FALSE
otherwise.
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().
使用 PHP 函数对变量 $x 进行比较
(上表没有找到原始来源,谁知道请告诉我)
如果变量是一个object该如何呢?
参考:
【1】http://php.net/manual/en/function.isset.php
【2】http://www.php.net/manual/en/function.empty.php
【3】http://www.php.net/manual/en/function.is-null.php
Returns TRUE if var
exists and has value other
than NULL, FALSE otherwise.
输入可以是多个变量,只有所有的变量为真的时候,返回真
empty()【2】
Returns FALSE if var
has a non-empty
and non-zero value.
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a
value in a class)
输入只能是一个变量
is_null() 【3】
Returns TRUE if var is
null , FALSE
otherwise.
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().
表达式 | gettype() | empty() | is_null() | isset() | if($x) Boolean |
---|---|---|---|---|---|
$x = ""; | string | TRUE | FALSE | TRUE | FALSE |
$x = null; | NULL | TRUE | TRUE | FALSE | FALSE |
var $x; | NULL | TRUE | TRUE | FALSE | FALSE |
$x is undefined | NULL | TRUE | TRUE | FALSE | FALSE |
$x = array(); | array | TRUE | FALSE | TRUE | FALSE |
$x = false; | boolean | TRUE | FALSE | TRUE | FALSE |
$x = true; | boolean | FALSE | FALSE | TRUE | TRUE |
$x = 1; | integer | FALSE | FALSE | TRUE | TRUE |
$x = 42; | integer | FALSE | FALSE | TRUE | TRUE |
$x = 0; | integer | TRUE | FALSE | TRUE | FALSE |
$x = -1; | integer | FALSE | FALSE | TRUE | TRUE |
$x = "1"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "0"; | string | TRUE | FALSE | TRUE | FALSE |
$x = "-1"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "php"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "true"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "false"; | string | FALSE | FALSE | TRUE | TRUE |
如果变量是一个object该如何呢?
表达式 | gettype() | empty() | is_null() | isset() | if($x) Boolean |
---|---|---|---|---|---|
$x = new object() | object | FALSE | FALSE | TRUE | TRUE |
【1】http://php.net/manual/en/function.isset.php
【2】http://www.php.net/manual/en/function.empty.php
【3】http://www.php.net/manual/en/function.is-null.php
相关文章推荐
- php用isset()判断变量是否定义的存在的坑
- 判断php变量是否定义,是否为空,是否为真的一览表
- 判断php变量是否为空/已定义
- js判断变量是否未定义
- mysql存储过程定义一个判断事务是否异常的错误变量
- Python 中如何判断变量是否已经定义
- php正则判断一个变量是否为正整数
- PHP判断变量是否存在并且己赋值安全的写法
- PHP 判断常量,变量和函数是否存在
- PHP 判断常量,变量和函数是否存在
- js判断变量是否未定义
- PHP判断变量是否存在及函数isset() 、empty()与is_null的区别
- PHP判断变量是否为长整形的方法
- (转载)PHP 判断常量,变量和函数是否存在
- PHP 判断常量,变量和函数是否存在
- Python判断变量是否已经定义的方法
- php判断变量是否是整数的两种方法
- PHP判断变量是否为空的几种方法区别
- JS中如何判断变量是否为空,有和PHP一样的isset()和empty()函数么?
- PHP 判断常量,变量和函数是否存在