Sometimes it is a bit confusing for developer to select right compare statement to check variables or arrays as there are lots of compare functions like "isset()", "!" operator, "is_null()", "empty()" etc.
So we can use a straight forward approach to do this:
1: For boolean value, use:
if ($var) {}
or
if (!$var) {}
2: Null or false value:
$var = '';
if (empty($var))
3: If variable is set or not:
if (isset($var)) {}
4: If we are just checking for NULL value
if (is_null($var)) {} or if ($var == NULL)
For more information to select right compare statement, you can read PHP type comparison
0 Comment(s)