• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

test for NULL

How do you test for a null value in php?

The following statement seems to be failing:

if (  $var !="NULL" )  

0
pillmill
Asked:
pillmill
1 Solution
 
hieloCommented:
For EQUAL:
if( $var === NULL )
{
 ...
}

OR
if( is_null($var) )
{
...
}


For NOT EQUAL:
if( $var !== NULL )
{
 ...
}

OR
if( !is_null($var) )
{
...
}
0
 
ajkuklaCommented:
http://www.php.net/manual/en/function.is-null.php

if (is_null($var)) {
   //do something
}
0
 
Dave BaldwinFixer of ProblemsCommented:
I think @hielo gave all the variations.  The reason your version is failing is because the quotes make it a text string and not the named constant NULL.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now