Google News
logo
PHP Program to NULL value
In PHP, `NULL` is a special value that represents a variable with no value or a non-existent value. A variable with a `NULL` value has been explicitly assigned the `NULL` value or has not been assigned a value at all.

Here's an example :
Program :
<?php
$name = null;
if (is_null($name)) {
    echo "Name is null";
} else {
    echo "Name is not null";
}
?>
Output :
Name is null
In the above example, we create a variable `$name` and assign it the `NULL` value explicitly. We then use the `is_null()` function to check if the variable has a `NULL` value and print a message accordingly.

PHP provides several functions to work with `NULL` values, such as `is_null()`, `unset()`, and `empty()`. The `unset()` function can be used to unset a variable and remove its value, effectively setting it to `NULL`.
Program :
<?php
$name = "John";
unset($name);
if (is_null($name)) {
    echo "Name is null";
} else {
    echo "Name is not null";
}
?>
Output :
Name is null
In the above example, we create a variable `$name` and assign it a string value. We then unset the variable using the `unset()` function and check if it has a `NULL` value using the `is_null()` function. The output will be "Name is null" because the variable `$name` has been unset and has no value.