is_nullFINDS if a given variable is a NULL.
This function returns a BOOLEAN value when it tests the following variable types:
STRING, NUMERIC, BOOLEAN, ARRAY, NULL, RESOURCE or OBJECT.
This functions returns TRUE wheather $var is a NULL or FALSE in not.
To visualize the result, in this tutorial, we use var_dump associated with an if loop structure as a conditional evaluation framework.
<?php
bool is_null ( mix $var )
where,
$var = The variable to be checked
?>
$var
The variable to be checked.
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
This is a simple example using
var_dump
to display the variable as is
- - - - - - - - - - - - - - - - - - - - - - - */
$var01f = [ 'c' => 299792458, 'G' => 6.67428E-11 ];
echo '<br><br>';
var_dump($var01f);
$var01g = NULL;
echo '<br><br>';
var_dump($var01g);
$var01hf = false;
echo '<br><br>';
var_dump($var01hf);
echo '<br><br>';
?>
RESULT
array(2) { ["c"]=> int(299792458) ["G"]=> float(6.67428E-11) }
NULL
bool(false)
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
This is a simple example using
if -> conditional evaluation
to display if the variable
is a NULL VALUE
- - - - - - - - - - - - - - - - - - - - - - - */
$var02f = [ 'c' => 299792458, 'G' => 6.67428E-11 ];
$var02gn = null;
$var02gN = NULL;
$var02hf = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if(is_null($var02f))
{
var_dump($var02f);
echo '<br>is a NULL value<br><br>';
}
else
{
var_dump($var02f);
echo '<br>is NOT a NULL value<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if(is_null($var02gn))
{
var_dump($var02gn);
echo '<br>is a NULL value<br><br>';
}
else
{
var_dump($var02gn);
echo '<br>is NOT a NULL value<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if(is_null($var02gN))
{
var_dump($var02gN);
echo '<br>is a NULL value<br><br>';
}
else
{
var_dump($var02gN);
echo '<br>is NOT a NULL value<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if(is_null($var02hf))
{
var_dump($var02hf);
echo '<br>is a NULL value<br><br>';
}
else
{
var_dump($var02hf);
echo '<br>is NOT a NULL value<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?>
RESULT
array(2) {
["c"]=>
int(299792458)
["G"]=>
float(6.67428E-11)
}
is NOT a NULL value
NULL
is a NULL value
NULL
is a NULL value
bool(false)
is NOT a NULL value
There is a simpler way of obtaining whether a variable is a NULL or not.
This will be seen the moment we study the user-defined functions.