Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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