- PHP

How to use isset() in PHP

The isset() function helps you determine whether the specific variable is set or not. It is helpful in many scenarios, and it helps us to avoid some errors caused by using undefined variables.

isset($variable);

Example:

Check with if and else whether the variable is set or not.

<?php

$myVariable = 'test';

if(isset($myVariable)) {
    echo $myVariable;
} else {
    echo "Variable doesn't exist!";
}

echo '<br>';

if(isset($myName)) {
    echo $myName;
} else {
    echo "I didn't define my name!";
}

?>

Output:

test
I didn’t define my name!