Jump to content

how to check a variable is NULL ?


garcon

Recommended Posts

if $facility_id is NULL, it may sometimes contain a blank space. if this is the case, then

if (!$facility_id) { echo "new"; }

may not work as blank space is still considered a value. i may be wrong, but i've faced this before. i therefore play it safe by comparing with a blank space

You can use empty() or !$varname to check if it's NULL, empty, or not defined.

 

If you want to check for null specifically, try $varname === NULL;

 

<?php

$var = NULL;

if ($var === NULL)
    echo 'works';

?>

 

echo'ed 'works' for me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.