<?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
?>
$age = 0;
// Evaluates as true because $age is set
if (isset($age)) {
echo '$age is set even though it is empty';
}
if (isset(true)) {
}
$variable=isset($otravariable);
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.
if (isset($val)) {
}
//with new features in new PHP versions like 7
//you can simplify writing of isset in the following way,
//old way of isset to display name if name variable is not null
echo isset($name) ? $name : "no name"
//new and simple way with null coalescing operator
echo $name ?? "no name"