In php program development, many friends are confused about how isset and empty are used or when isset and empty functions are used. I will introduce the differences between the two. isset-check whether PHPisset () is set for the variable ()... in php program development, many friends are confused about how isset and empty are used or when isset and empty functions are used. I will introduce the differences between the two.
Isset-check whether the variable is set
PHP isset () is used to detect whether one or more variables are set. if the detected variables exist, TRUE is returned; otherwise, FALSE is returned.
The sample code is as follows:
The elements in the array are also valid. the code is as follows:
$ A = array ('test' => 1, 'Hello' => NULL );
Var_dump (isset ($ a ['test'); // TRUE
Var_dump (isset ($ a ['Foo'); // FALSE
Var_dump (isset ($ a ['Hello'); // FALSE
// 'Hello' is equal to NULL, so it is considered to be unassigned.
// If you want to check the NULL key value, try the following method.
Var_dump (array_key_exists ('hello', $ a); // TRUE
Note:
• Isset () can only be used to detect Variables. passing any other parameter will cause parsing errors.
• Isset () is a language structure rather than a function, so it cannot be called by variable functions.
Empty-check whether a variable is empty
If the variable is not null or a non-zero value, empty () returns false.
If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.
Empty () is the antonym of (boolean) var except when the variable is not set. the code is as follows:
The instance comparison code is as follows:
";} Else {echo" variable does not exist!
";} If (emptyempty ($ is_var) {echo" variable is empty!
";} Else {echo" variable is not empty!
";}?>
Permanent address:
Reprint at will ~ Please bring the tutorial URL ^