What you’re looking for is:
if($variable === NULL) {...}
Note the ===
.
When use ==
, as you did, PHP treats NULL, false, 0, the empty string, and empty arrays as equal.
More Related Contents:
- json_encode is returning NULL?
- Why I am getting Cannot pass parameter 2 by reference error when I am using bindParam with a constant value?
- Null vs. False vs. 0 in PHP
- PHP json_decode() returns NULL with valid JSON?
- PHP/MySQL Insert null values
- How to store NULL values in datetime fields in MySQL?
- check if variable empty
- using nulls in a mysqli prepared statement
- In PHP, what is the differences between NULL and setting a string to equal 2 single quotes
- PHP Check for NULL
- Check if value isset and null
- PHP json_decode() returns NULL with seemingly valid JSON?
- Passing null to non-nullable internal function parameters – Updating Existing Code Base to php 8.1
- MySQL and PHP – insert NULL rather than empty string
- How to select rows where column value IS NOT NULL using CodeIgniter’s ActiveRecord?
- PHP constructor to return a NULL
- What is the difference between null and empty?
- MySQL, how to insert null dates
- Why does PHP not complain when I treat a null value as an array like this?
- How can I debug exec() problems?
- PDO MySQL: Use PDO::ATTR_EMULATE_PREPARES or not?
- How to strip a tag and all of its inner html using the tag’s id?
- How to successfully rewrite old mysql-php code with deprecated mysql_* functions?
- PHP Configuration: It is not safe to rely on the system’s timezone settings [duplicate]
- Use Javascript to access a variable passed through Twig
- mysql_num_rows() expects parameter 1 to be resource, boolean given in [duplicate]
- ffmpeg Progress Bar – Encoding Percentage in PHP
- How to separate letters and digits from a string in php
- utf8_(en|de)code removed from php7?
- PHP Find all occurrences of a substring in a string