Determine whether php variables are defined. is it empty isset () [1] Returns? TRUE? If? Var? Existsandhasvalueotherthan? NULL ,? FALSE? Otherwise. the input can be multiple variables. If all the variables are true, true emp is returned to determine whether php variables are defined and empty.
Isset () [1]
Returns?TRUE? If?Var? Exists and has value other?NULL,?FALSE? Otherwise.
The input can be multiple variables. only when all the variables are true returns true.
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)
The 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 not been set to any value yet.
It has been? Unset ().? ?
?
?
$ X
Using PHP functions for variables?? For comparison
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 original source is not found in the table above. please let me know)
What if the variable is an object?
?
Expression gettype () empty () is_null () isset () if ($ x) Boolean
$ X = new object ()? |
Object |
FALSE |
FALSE |
TRUE |
TRUE |
?
Refer:
[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