xxxxxxxxxx
$variable = "Hello World";
if(isset($variable)){
echo "Variable is set.";
} else {
echo "Variable is not set.";
}
xxxxxxxxxx
<?php
$var = '';
// This will evaluate to TRUE so the text will be printed.
if (isset($var)) {
echo "This var is set so I will print.";
}
// In the next examples we'll 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
?>
xxxxxxxxxx
$age = 0;
// Evaluates as true because $age is set
if (isset($age)) {
echo '$age is set even though it is empty';
}
isset() php
xxxxxxxxxx
$foo = false;
if (isset($foo)) {
echo "foo is set";
} else {
echo "foo is not set";
}
// When you pass a value of false to the isset() function in PHP, it will return true because false is a valid value that has been set.
xxxxxxxxxx
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.
The isset function in PHP is used to determine whether a variable is set or not. A variable is considered as a set variable if it has a value other than NULL. In other words, you can also say that the isset function is used to determine whether you have used a variable in your code or not before