Null is a special data type that presents a variable with no value.
A variable is null if it’s assigned a constant null or it’s not defined yet.
$a = null;
echo $a;
var_dump($a); // NULL
var_dump($b); // NULL because it's undefined.
We can use the function is_null()
to check if a variable is null.
$a = null;
var_dump(is_null($a)); // bool(true)
Or we can also use a triple equal sign comparison operator.
$a = null;
var_dump($a === null); // bool(true)
When null is cast into a string, it will be converted into an empty string.
It will be 0, false, and an empty array if we cast null into an integer, a boolean, or an array.
$a = null;
var_dump((string)$a); // string(0) ""
var_dump((int)$a); // int(0)
var_dump((bool)$a); // bool(false)
var_dump((array)$a); // array(0) { }