Isset
(PHP 3, PHP 4, PHP 5)
Isset--Detects whether a variable is set
Describe
BOOL Isset (mixed var [, mixed Var [, ...]])
Returns TRUE if VAR exists, otherwise returns FALSE.
If you have freed a variable using unset (), it will no longer be isset (). If you use Isset () to test a variable that is set to NULL, it returns FALSE. Also note that a null byte ("" ") is not equivalent to PHP's null constant.
Warning: isset () can only be used for variables because passing any other parameter will result in a parse error. To detect if a constant is set, use the defined () function.
Copy Code code as follows:
<?php
$var = ';
The result is TRUE, so the text behind will be printed.
if (Isset ($var)) {
Print "This var is set set and so I'll print.";
}
In the example below, we will use Var_dump to output the return value of Isset ().
$a = "Test";
$b = "Anothertest";
Var_dump (Isset ($a)); TRUE
Var_dump (Isset ($a, $b)); TRUE
unset ($a);
Var_dump (Isset ($a)); FALSE
Var_dump (Isset ($a, $b)); FALSE
$foo = NULL;
Var_dump (Isset ($foo)); FALSE
?>
This is also valid for elements in the array:
Copy Code code as follows:
<?php
$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 key ' hello ' is equal to NULL, so it is considered an open value.
If you want to detect NULL key values, try the bottom method.
Var_dump (array_key_exists (' hello ', $a)); TRUE
?>
Note: Because this is a language structure and not a function, it cannot be invoked by a "variable function".
Reasonable application of PHP function Isset () can help us to detect whether the variable is set. Returns FALSE if the variable does not exist, and returns ture if the variable exists and the value is not NULL.
By learning about the PHP language, you should know that it is a function based HTML scripting language. The vast library of functions supports the implementation of the PHP language function. Here's a brief introduction to the usage of PHP function isset ().
Format: bool Isset (mixed var [, mixed Var [, ...]])
Function: Detect whether the variable is set
return value:
Returns FALSE if the variable does not exist
Returns FALSE if the variable exists and its value is null
Returns ture if the variable exists and the value is not NULL
When you check multiple variables at the same time, each item returns TRUE when it meets the previous requirement, otherwise the result is FALSE
Version: PHP 3, PHP 4, PHP 5
More Description:
After you use unset () to free a variable, it is no longer a isset ().
php function Isset () can only be used for variables, and passing any other parameter will result in parsing errors.
Detects whether a constant is set to use the defined () function.
Unset ()
Destroys the specified variable. Note in PHP 3, unset () returns True (actually an integer value of 1), whereas in PHP 4, unset () is no longer a real function: it is now a statement. So that there is no return value, trying to get the return value of unset () will result in a parse error.