How to check whether a variable is set or not in PHP

How to check whether a variable is set or not in PHP

In this post we will give you information about How to check whether a variable is set or not in PHP. Hear we will give you detail about How to check whether a variable is set or not in PHPAnd how to use it also give you demo for it if it is necessary.

Use the PHP isset() function

You can use the PHP isset() function to test whether a variable is set or not. The isset() will return FALSE if testing a variable that has been set to NULL.

Let’s check out an example to understand how this function basically works:

<?php
$var1 = '';
if(isset($var1)){
    echo 'This line is printed, because the $var1 is set.';
}
echo "<br>";
 
$var2 = 'Hello World!';
if(isset($var2)){
    echo 'This line is printed, because the $var2 is set.';
}
echo "<br>";
 
// Unset the variable
unset($var2);
 
if(isset($var2)){
    echo 'This line is printed, because the $var2 is set.';
} else{
    echo 'This line is printed, because the $var2 is not set.';
}
echo "<br>";
 
$var3 = NULL;
if(isset($var3)){
    echo 'This line is printed, because the $var3 is set.';
} else{
    echo 'This line is printed, because the $var3 is not set.';
}
?>

i hope you like this small article.

Hope this code and post will helped you for implement How to check whether a variable is set or not in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US