is_null($x) vs $x === null in PHP
This is_null() function is an inbuilt function in PHP which is used to find whether a variable is NULL or not. It returns True if the given variable is null, otherwise return False.
Syntax:
bool is_null( $var )
Example 1:
<?php // PHP program to illustrate // is_null() function // Declare variable and initialize it $x = NULL; $y = 15; // Use is_null() function and // display the result var_dump(is_null($x)); var_dump(is_null($y)); ?> |
bool(true) bool(false)
$x === null
It is an identical comparison operator and it returns true if the value of $x is equal to NULL. Null is a special data type in PHP which can have only one value that is NULL. A variable of data type NULL is a variable that has no value assigned to it. Any variable can be empty by setting the value NULL to the variable.
Syntax:
$var === null
Example:
<?php // PHP program to demonstrate // === operator // Declare variable and initialize it $x = "GeeksforGeeks"; if ($x === null) echo "True \n"; else echo "False \n"; // Declare variable and initialize it $y = NULL; if ($y === null) echo "True"; else echo "False"; ?> |
False True
Recommended Posts:
- How to check empty/undefined/null string in JavaScript?
- Ternary operator vs Null coalescing operator in PHP
- ReactJS | forms
- Difference between Iterator and Enumeration in Java with Examples
- How to remove Objects from Associative Array in JavaScript ?
- How to change the Content of a <textarea> using JavaScript ?
- How to check input file is empty or not using JavaScript/jQuery ?
- How to print JavaScript console with PHP ?
- How to set PHP development environment in windows ?
- How to set font size based on window size using JavaScript ?
- How to check two elements are same using jQuery/JavaScript ?
- How to globally replace a forward slash in a JavaScript string ?
- Difference between DOM parentNode and parentElement in JavaScript
- How to Encrypt and Decrypt a PHP String ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



