[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

NULL value

Hello,

I need to know what's the right script to check if the value is null or not

$isDefault = NULL
or $isDefault=[NULL]
or $isDefault='NULL'
ot $isDefault==NULL

Thanks
0
usmbay
Asked:
usmbay
4 Solutions
 
waygoodCommented:
if($isDefault==null)
0
 
usmbayAuthor Commented:
but in the table looks like this [NULL]

should I write it null or NULL or there's no different
0
 
MacAnthonyCommented:
If this is coming from a database query and the value is null, then it will apply null to the value in the array. If it is important to know if the value is in fact null, then you may want to use:
$isDefault === null // this will check type
or
is_null( $isDefault )

Otherwise values of '' and 0 could also be interpreted as null values.

And yes, null and NULL are both valid ways of expressing null.
0
 
nplibCommented:
if (!$isDefault) {
    echo "The value is Null";
}

You need the BANG "!" in front of the variable

and

if ($isDefault) {
     echo "the value is not null";
}

just the  variable in the if statement will check if the variable has any value.

though when checking for a null or empty value you should do this
if ((!$isDefault) || ($isDefault == "")) {
    echo "The value is Null";
}
this checks if it is null or is empty, cause sometimes a variable can have a value that is blank and not be null.
0
 
paradoxengineCommented:
you could even use the empty($isDefault) function - returns true if empty, null, 0 or 0 sized - but it depends on the actual implementation of your code.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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