Change language

is_null ($ x) vs $ x === null in PHP

|
This is_null() function is a built-in PHP function that is used to determine if a variable is NULL or not. Returns True if the specified variable is zero, otherwise returns False.Syntax:
bool is_null ($var )
Example 1:
// PHP illustration program
// is_null() function 
// Declare a variable and initialize it $x = NULL; $y = 15;  
// Use the is_null() function and
// display the result var_dump ( is_null ( $x )); var_dump ( is_null ( $y ));  
?>
Exit:
bool (true ) bool (false)
$x === zero This is the identical comparison operator and it returns true if $x is NULL. Null - it is a special data type in PHP that can only have one NULL value. Variable of data type NULL - it is a variable that has not been assigned a value. Any variable can be empty by setting it to NULL.Syntax:
$var === null
Example:
// PHP program for demonstration
// === operator 
// Declare a variable and initialize it $x = "GeeksforGeeks" ; if ( $x === null) echo " True " ; else echo " False " ;  
// Declare a variable and initialize it $y = NULL; if ( $y === null) echo " True " ; else echo " False " ;  
?>
Exit:
False True
SO 1 data error