The Isset function detects if a variable is set. Format: bool Isset (mixed var [, mixed Var [, ...]) return value: Returns False if the variable exists and its value is NULL, returns FALSE if the variable exists and the value is not NULL, returns TRUE if the ture checks multiple variables at the same time, or False if unset is already used ( After releasing a variable, it will no longer be isset (). If you use Isset () to test a variable that is set to NULL, FALSE is returned. Also note that a null byte ("s") is not equivalent to a null constant in PHP. Warning: isset () can only be used for variables, because passing any other parameter will result in parsing errors. To detect if a constant is set, use the defined () function. Example 1:
- $var = ";
- if (Isset ($var)) {
- Print "This var was set set so I'll print.";
- }//in the example below, we will use the Var_dump function to output the return value of the 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
- ?>
Copy CodeExample 2:
$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 ' equals NULL, so it is considered to be unassigned.
- If you want to detect NULL key values, you can try the methods below.
- Var_dump (array_key_exists (' hello ', $a)); TRUE
- ?>
Copy Code |