This function is used to checks a variable value is set or not. which means that it has to be variable is declared and is not NULL.
This isset() function returns true if the variable value is set and is not NULL, otherwise it returns false.
File Name :
$name = "mahtab habib";
// it return True because $name is set
if (isset($name)) {
echo "my name is".$name;
}
$x = null;
// it return False because $x is NULL
if (isset($x)) {
echo "Variable 'x' is set.";
}
?>
unset() Function
The unset() function unset a variable. this function is used to remove the variable value.
File Name :
$str = "Hi sana!";
echo "The value of variable 'str' before unset: " . $str . " ";
unset($str);
echo "The value of variable 'str' after unset: " . $str;
?>
Output :-
The value of variable 'str' before unset: Hi sana!
The value of variable 'str' after unset:
Example :-
// Set session variables
$_SESSION["fname"] = "mahtab";
empty() function is a predefine php function. it check the variable value is empty or not. if variable is empty then it return True otherwise it return False.
is_null() Check a variable is NULL or not. if the variable has been set with NULL. in this case is_null() is used to check variable is empty or not.
isset() function is used to check variable contain value or not. but is_null() check variable contain null or not.
File Name :
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)
$variable = NULL;
is_null($variable);
$a = 0;
echo "a is " . is_null($a);
$b = null;
echo "b is " . is_null($b);
$c = "null";
echo "c is " . is_null($c);
$d = NULL;
echo "d is " . is_null($d);