This article mainly introduces the usage of isset () and unset () functions in PHP in detail. if you need them, you can refer to them and hope to help you.
Isset
(PHP 3, PHP 4, PHP 5)
Isset -- check whether the variable is set
Description
Bool isset (mixed var [, mixed var [,...])
If var exists, TRUE is returned; otherwise, FALSE is returned.
If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.
Warning: isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.
The code is as follows:
$ Var = '';
// The result is TRUE, so the subsequent text is printed.
If (isset ($ var )){
Print "This var is set so I will print .";
}
// In the following example, var_dump is used to output the return value of isset.
$ A = "test ";
$ B = "anothertest ";
Var_dump (isset ($ a); // TRUE
Var_dump (isset ($ a, $ B); // TRUE
Unset ($ );
Var_dump (isset ($ a); // FALSE
Var_dump (isset ($ a, $ B); // FALSE
$ Foo = NULL;
Var_dump (isset ($ foo); // FALSE
?>
This is also effective for elements in the array:
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
// The value of the 'Hello' key is NULL, so it is considered as an unset value.
// If you want to check the NULL key value, try the following method.
Var_dump (array_key_exists ('hello', $ a); // TRUE
?>
Note: Because this is a language structure rather than a function, it cannot be called by the variable function.
The rational application of the PHP function isset () can help us to check whether the variables are set. If the variable does not exist, FALSE is returned. if the variable exists and the value is not NULL, true is returned.
Through learning the PHP language, you should know that it is a function-based HTML scripting language. The huge function library supports the implementation of PHP functions. The following describes how to use the PHP function isset.
Format: bool isset (mixed var [, mixed var [,...])
Function: checks whether variables are set.
Return value:
If the variable does not exist, FALSE is returned.
If the variable exists and its value is NULL, FALSE is returned.
If the variable exists and the value is not NULL, true is returned.
When multiple variables are checked at the same time, TRUE is returned only when each individual item meets the previous requirement; otherwise, the result is FALSE.
Version: PHP 3, PHP 4, PHP 5
More instructions:
When unset () is used to release a variable, it is no longer an isset ().
The PHP function isset () can only be used for variables. passing any other parameter will cause a parsing error.
Checks whether the defined () function has been set for constants.
Unset ()
Destroys the specified variable. Note that in PHP 3, unset () will return TRUE (actually an integer value of 1). in PHP 4, unset () is no longer a real function: it is now a statement. In this way, no return value is returned. an attempt to obtain the return value of unset () will cause a parsing error.