What is NULL in PHP?

NULL is a special data type in PHP that has only one value, NULL. It means “no value”. NULL is not same as 0, empty string or false.

A variable is NULL in three cases: when you assign NULL to it, when it was never created, or when you remove it with unset().

<?php
$x = "Hello PHP!";
$x = null;

var_dump($x);
var_dump(is_null($x));
var_dump(isset($x));
?>

Output:

Tutorials Class - Output Window

NULL
bool(true)
bool(false)

To check for NULL use is_null() or === null. The isset() function returns false for a NULL variable.


Learn more about the similar topics:
Tutorials
PHP Variables
PHP Data Types
PHP Constants
PHP isset() Function
PHP empty() Function
PHP is_null() Function
Exercises & Assignments
Write a program to print “Hello PHP” using variable
Write a program to print a string using echo+variable.
Write a program to print two variables in single echo
Interview Questions & Answers
How to check if a variable is empty in PHP?
Is PHP a case sensitive language?
What are the different data types in PHP?
How to define a Constant in PHP?
What is the difference between $var and $$var in PHP?
Which special characters are allowed in PHP variable names?
Can we print multiple variables in a single echo statement in PHP?