• In PHP null () function is an inbuilt function which is used to find whether a variable is NULL or not.
  • If it returns True the given variable is null, otherwise it returns False.
  • If the value of $x is equal to NULL it returns true and it is an identical comparison operator.
  • In PHP null is a special data type which can have only one value that is NULL.
  • NULL data type is a variable that has no value assigned to it and then any variable can be empty by setting the value NULL to the variable.

Sample Code

<!DOCTYPE html>
<html>
<body>

<?php
$apple = 0;
echo "apple is " . is_null($a) . "<br>";

$orange = null;
echo "orange is " . is_null($b) . "<br>";

$grape = "null";
echo "grape is " . is_null($c) . "<br>";

$watermelon = NULL;
echo "watermelon is " . is_null($d) . "<br>";
?>

</body>
</html>

Output

Categorized in: