Determine if the PHP variable is defined and is empty
Isset () "1"
Returns? TRUE? If? var? exists and have value other than? NULL,? FALSE? otherwise.
Input can be multiple variables, only when all variables are true, return true
Empty () "2"
Returns? FALSE? If? varhas a non-empty and Non-zero value.
The following things is 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)
Input can only be a variable
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 no been set to any value yet.
It has been? unset (). ? ?
?
?
$x
Use PHP functions for variables?? to compare
Expression 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 |
?
(The above table did not find the original source, who knows please tell me)
What if the variable is an object?
?
Expression GetType () empty () Is_null () isset () if ($x) Boolean
$x = new Object ()? |
Object |
FALSE |
FALSE |
TRUE |
TRUE |
?
Reference:
"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
?
?
Http://blog.csdn.net/autofei/archive/2010/05/24/5619004.aspx