The isset() function is an built-in function in PHP which is used to check whether a variable is set or not. The isset() will return true if testing a variable is set and not null.
Example:
<?php
$var1 = '';
if(isset($var1)){
echo '$var1 is set.'; // Output: $var1 is set.
}
echo "<br>";
$var2 = 'PHP Tutorials';
if(isset($var2)){
echo '$var2 is set.'; // Output: $var2 is set.
}
echo "<br>";
// Unset the variable
unset($var2);
if(isset($var2)){
echo '$var2 is set.';
} else{
echo '$var2 is not set.'; // Output: $var2 is not set.
}
echo "<br>";
$var3 = NULL;
if(isset($var3)){
echo '$var3 is set.';
} else{
echo '$var3 is not set.'; // Output: $var3 is not set.
}
?>
Tags: how to use isset() function if (variable) php php check if array is empty php check if string is empty or whitespace php check if variable exists php check if variable is true or false php empty php isset vs empty php isset() function
About Praveen Kumar
I am a fullstack web developer with a passion for SEO, creating stunning websites, and organic marketing. I am a perfectionist.
View all posts by Praveen Kumar