Misunderstanding isset() behavior in Php

The isset() function in PHP is used to check if a variable has been set, meaning that it has been declared and is not equal to NULL. If the variable is set, isset() will return TRUE, and if the variable is not set, isset() will return FALSE.

For example, the following code would return TRUE because the variable $example has been set to the value ‘Hello, World!’:

$example = 'Hello, World!';
if (isset($example)) {
    echo '$example is set.';
}

However, if the variable is not set, isset() will return false.

if (isset($example2)) {
    echo '$example2 is set.';
}else{
    echo '$example2 is not set.';
}

It’s important to note that isset() will only return FALSE if the variable has not been set or if it has been set to NULL. If a variable has been set to an empty string or to 0, isset() will return TRUE.

isset() also can take more than one variable as input, in that case it will check all the variables passed as input and if any of the variable is not set it will return false

$example1 = 'Hello, World!';
$example2 = NULL;
if (isset($example1,$example2)) {
    echo 'Both $example1 and $example2 are set.';
}else{
    echo 'Either $example1 or $example2 is not set.';
}

This would return false as $example2 is set to NULL.