Difference Between unset and null
unset() | null |
---|---|
Destroys a variable and frees up memory | Assigns a null value to a variable |
Makes a variable undefined | Indicates that a variable has no value assigned |
Cannot be used with non-variable expressions | Can be assigned to any variable or expression |
What is the Difference Between unset and null in PHP ?
In PHP, unset
and null
are used to handle variables differently. unset
is a language construct used to destroy a variable, while null
is a special value representing a variable with no value assigned to it.