Quick Reach
What is the isset function?
PHP provides a function isset() to see if a variable is set or not. It means PHP isset() function checks if a variable is already assigned a value or not?
See an example of isset function
How to use the isset function?
Following is the general syntax of using the isset function:
isset($variable_name);
You can check one or more variables at one call.
Example of using isset function in PHP
A very simple program to test isset PHP function is as follows:
Experience this example online
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<?php
$var1 = 1;
if (isset($var1)) {
echo "var1 is set"."<br>";
} else {
echo "var1 is not set"."<br>";
}
if (isset($var2)) {
echo "var2 is setn";
} else {
echo "var2 is not setn";
}
?>
|
Output
var1 is set
var2 is not set
In the above example, you can see the var1 is assigned a value before using the isset with the if statement. As it was set, i.e. assigned a value, the if statement returned true.
On the other hand, the var2 is not assigned any value and in the if statement it executed the else part that means the condition was false.
Please note if a variable is unset by using the unset() function it can no longer be set.
Leave A Comment?