PASSWORD RESET

Your destination for complete Tech news

PHP

How to check whether a variable is null in PHP?

435 0
< 1 min read

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

For example:

$var = null;

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

This would output $var is null.

You can also use the === operator to check whether a variable is null. This operator returns true if the variable is null and of the null type, and false otherwise.

For example:

$var = null;

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

This would also output $var is null.

Leave A Reply

Your email address will not be published.

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