Share on Google+Share on Google+

PHP NULL Type

Advertisement
In this tutorial you will come to know about NULL values and how to make a variable NULL, how to check a variable etc.

PHP NULL type:

In PHP 4 a special type of value is introduced, which indicates that a variable does not consists of any value or NULL value. NULL is the only value of NULL datatype.

A variable is considered to be NULL if we use unset() method on a variable, or a NULL value is assigned to the variable, no value is yet assigned to it.

Two special functions are used in this context, is_null() and unset(). is_null() function is used to check whether a  variable is NULL assigned or it has some value.

PHP Null Type Example:

<?php

$a;

echo "1=True and Blank=False".is_null($a)."<br/>";

$a=23;

echo "1=True and Blank=False".is_null($a)."<br/>";

$a=NULL;

echo "1=True and Blank=False".is_null($a)."<br/>";

$a=12;

echo "1=True and Blank=False".is_null($a)."<br/>";

unset($a);

echo "1=True and Blank=False".is_null($a)."<br/>";

?>

 

Output: 

1=True and Blank=False1
1=True and Blank=False
1=True and Blank=False1
1=True and Blank=False
1=True and Blank=False1

Advertisements

Advertisement

Posted on: March 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.