PHP is_null() Function
Syntax
is_null(variable);
Parameter | Description |
Variable | Any variable (Required) |
Example
<?php $a = " NULL "; if(is_null($a)) { echo " Null "; } else { echo " Not null "; } ?>
Output
In above example $a is a variable and NULL is a string so that result will be not null. Double or single quotes represent the string.
Definition
It returns TRUE if the variable is NULL otherwise return false.
Usage
Is_null() function is used to check the variable is empty or not.
An undeclared $variable will return TRUE but may return an error.
Example of is_null function
<?php $a=""; var_dump(is_null($a)); ?>
- Example
- Run
In above example $a is a variable but not null so that result will be false.
More example of is_null function
<?php $number = NULL; var_dump(is_null($number)); $number1 = " John " ; var_dump(is_null($number1)); ?>
- Example
- Run
$number is a variable and NULL is not a string, its represent the variable with no value. SO result will be true.
$number is a string variable that hold some value so that result will be false.
All of these function works same as above.
- is_array
- is_bool
- is_callable
- is_double
- is_float
- is_int
- is_integer
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string