The isset function checks whether the variable is set. Format: bool isset (mixed var [, mixed var [,...]) Return value: If the variable does not exist, FALSE is returned. if the variable exists and its value is NULL, FALSE is also returned. if the variable exists and the value is not NULL, true is returned when multiple variables are checked simultaneously, TRUE is returned only when each individual item meets the previous requirement. Otherwise, the result is FALSE. if a variable is released using unset (), it is no longer 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. Example 1:
- $ Var = '';
- If (isset ($ var )){
- Print "This var is set so I will print .";
- } // In the following example, we will use the var_dump function to output the returned 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
- ?>
Example 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' 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
- ?>
|