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
usmbayAsked:
Who is Participating?
 
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
 
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
 
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
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.

All Courses

From novice to tech pro — start learning today.