- $var = ";
- The result is true, so the text behind will be printed.
- if (Isset ($var)) {
- Print "This var was set set 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
- ?>
Copy CodeThis is equally valid for elements in an array:
- $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 to be an unassigned value.
- If you want to detect null key values, you can try the methods below.
- Var_dump (array_key_exists (' hello ', $a)); True
- ?>
Copy CodeNote: Because this is a language structure and not a function, it cannot be called by a "variable function". Reasonable application of PHP function Isset () can help us to detect whether a 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 the language of PHP, you should know that it is a function-based HTML scripting language. The large library of functions supports the implementation of PHP language functions. Under Related usage of PHP function isset (). Format: bool Isset (mixed var [, mixed Var [, ...]) Function: Detects if a variable has a return value: If the variable does not exist, it returns False if the variable exists and its value is NULL, and returns FALSE if the variable exists and the value is not NULL, returns True if the ture checks for multiple variables at the same time, or if each item conforms to the previous requirement, the result is False version: PHP 3, PHP 4, PHP 5 More information: After releasing a variable with unset (), it will no longer be isset (). PHP functions Isset () can only be used for variables, and passing any other parameter will result in parsing errors. Detects if 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. Thus there is no return value, and attempting to get the return value of unset () will result in a parse error. |