The Null Value in PHP
In PHP, there is another special value
null
, which means "nothing".
For example, we can assign this value to a variable
to signify that there is nothing there.
Let's look at an example:
<?php
$test = null;
?>
Let's output the value of our variable using
var_dump
:
<?php
$test = null;
var_dump($test); // will output null
?>
But with echo
we won't see anything:
<?php
$test = null;
echo $test; // will output emptiness
?>
By default, variables that have not been
declared in the code have the value null
:
<?php
var_dump($test); // will output null
?>
Assign the value null
to a variable.
Output this variable to the screen.
Output the value of any undeclared variable to the screen.