Solved

test for NULL

Posted on 2011-09-08
3
254 Views
Last Modified: 2012-05-12
How do you test for a null value in php?

The following statement seems to be failing:

if (  $var !="NULL" )  

0
Comment
Question by:pillmill
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 36505130
For EQUAL:
if( $var === NULL )
{
 ...
}

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


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

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

Expert Comment

by:ajkukla
ID: 36505190
http://www.php.net/manual/en/function.is-null.php

if (is_null($var)) {
   //do something
}
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36505470
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now