<? PHP
/**
For beginners, isset, empty, and is_null cannot be used properly to make a correct judgment on the return values of null and false values. Here I have summarized some knowledge points by myself, as a future knowledge point
*/
// 1. Set the data type, for example, the commonly used type
$;
$ B = false;
$ C = '';
$ D = 0;
$ E = NULL;
$ F = array ();
// 2. Test the returned values of the above data types for different functions, and print them with var_dump (). You will know the difference between print_r and the project!
// Print the empty () function below 2.1
Var_dump (empty ($ A); // Output True
Var_dump (empty ($ B); // Output True
Var_dump (empty ($ C); // outputs true
Var_dump (empty ($ D); // Output True
Var_dump (empty ($ E); // Output True
Var_dump (empty ($ F); // outputs true
// Analysis: if the data type is null or false, empty () Outputs true.
// 2.2 test the isset data return type
Var_dump (isset ($ A); // outputs false
Var_dump (isset ($ B); // outputs true
Var_dump (isset ($ C); // outputs true
Var_dump (isset ($ D); // outputs true
Var_dump (isset ($ E); // outputs false
Var_dump (isset ($ F); // outputs true
/** Analysis: 1. isset () can only be used to determine whether it is null or undefined. to check whether the variable has been defined, you can use the defined () function;
2. If you want to determine whether a variable is set (declared), use isset
3. To determine whether a variable is assigned a value and is not empty, use empty
4. If you want to determine whether a variable is set and not empty, you can use isset first and then use empty
*/
// 2.3 Test the is_null Return Value Type
Var_dump (is_null ($ A); // outputs true, but is undefined because of the error level.
Var_dump (is_null ($ B); // output false
Var_dump (is_null ($ C); // outputs false
Var_dump (is_null ($ D); // output false
Var_dump (is_null ($ E); // outputs true
Var_dump (is_null ($ F); // outputs false
/**
Analysis: it is only used to determine whether it is null or undefined. Its usage is basically the same as that of Iset.
*/
Empty is_null isset
$ A = "" True False true
$ A = NULL true false
VaR $ a true false
$ A = array () True False true
$ A = false True False true
$ A = 10 False false true
$ A = 1 False false true
$ A = 0 True False true
$ A = "" True False true
$ A = "true" False false true
$ A = "false" True False true
Small knowledge points of isset, empty, and is_null