Home Tutorial Php PHP Null Variables

 
 

Share on Google+Share on Google+
PHP Null Variables
Posted on: January 14, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for PHP Null Variables:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 14, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com