Home Tutorial Php PHP Null Variables

 
 

PHP Null Variables
Posted on: January 14, 2010 at 12:00 AM
PHP Null variable is a type that only stores the null value. The Null value indicates that the used variable has no value. The variable only considered null when :

PHP Null Variables

PHP Null variable is a type that only stores the null value. The Null value indicates that the used variable has no value. The variable only considered null when :

1. The variable assigned as a null.

2. The value has not set or used unset() function.

It is introduced in PHP 4 and further versions and it is also not case-sensitive.

Let's see the example to understand the Null type :

<?php

    $null = NULL;

?>

If you run this code on your server, it will not show anything on the screen because the variable assigned as a null. Even you can leave the value blank.

Let's see few more example to understand the NULL type in a better way :

<?php

error_reporting(E_ALL);

$text = NULL;

 

if($text == null)

{

    echo "The variable has no value!"."<br/>";

}

if($text === null)

{

    echo "Yes, the variable is equal to null!"."<br/>";

}

if(isset($null))

{

    echo "The variable has been set!";

}

    if(empty($null))

{

    echo "The variable is empty!";

}

?>

The output of the above example is : The variable has no value!
                                                        Yes, the variable is equal to null!
                                                        The variable is empty!

In the above example we only compare the variable value with the null and it gives different-different result to us.

Related Tags for PHP Null Variables:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.