PASSWORD RESET

Your destination for complete Tech news

PHP

How to check whether a variable is set in PHP?

498 0
< 1 min read

To check whether a variable is set in PHP, you can use the isset() function. This function returns true if the variable is set, and false otherwise.

A variable is considered set if it has been assigned a value, even if the value is null.

For example:

$var = '';

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

This would output $var is set.

You can also use the empty() function to check whether a variable is set and is not null. This function returns true if the variable is set and is not null, and false otherwise.

For example:

$var = '';

if (empty($var)) {
    echo '$var is empty';
} else {
    echo '$var is not empty';
}

This would output $var is not empty.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.