Solved

test for NULL

Posted on 2011-09-08
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 83

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 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