In this article, you will learn how to check if a variable is empty or not.
The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.
what is the syntax of the ISSET() function in php?
isset(variable, ....);
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
… | Optional. Another variable to check |
examples of the ISSET() function
Example 1. In this example, we check whether a variable is empty. Also, check whether the variable is set/declared.
<?php
$a = 0;
// True because $a is set
if (isset($a)) {
echo "Variable 'a' is set.<br>";
}
$b = null;
// False because $b is NULL
if (isset($b)) {
echo "Variable 'b' is set.";
}
?>