The defined () function checks whether a constant exists.
If a constant exists, true is returned; otherwise, false is returned.
| The code is as follows: |
Copy code |
If (defined ('myconstant ')){ Echo "constant MYCONSTANT exists "; } Else { Echo "constant MYCONSTANT does not exist "; } Echo "<br/> ";
|
The isset function checks whether variables are set.
1. If the variable does not exist, FALSE is returned.
2. If the variable exists and its value is NULL, FALSE is also returned.
3. If the variable exists and the value is not NULL, true is returned.
4. 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
| The code is as follows: |
Copy code |
<? Php $ 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 ?> |
This is also effective for elements in the array:
| The code is as follows: |
Copy code |
<? 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 // '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 ?> |
Function_exists
| The code is as follows: |
Copy code |
<? Php If (function_exists ('test _ func ')){ Echo "the test_func function exists "; } Else { Echo "the test_func function does not exist "; } ?> |
Filter_has_var function
The filter_has_var () function checks whether a variable of the specified input type exists.
If yes, true is returned. Otherwise, false is returned.
| The code is as follows: |
Copy code |
<? Php If (! Filter_has_var (INPUT_GET, "name ")) { Echo ("Input type does not exist "); } Else { Echo ("Input type exists "); } ?> |
Output is. Input type exists