These three functions are easy to confuse in PHP, but they are often encountered during development and written interviews. Let’s summarize them here.
When the variable $a=null, the program result is
is_null($a) true
##isset($a )false
empty($a)true
Program result when variable $a=''(empty string) For
false##isset($a)
trueempty($a)
true
When variable $a= ' ' (there is a space in the middle), the program result isis_null($a)
falseisset($a)
trueempty($a)
false
When the variable $a=[] (empty array) the program result isis_null($a)
false##isset($a) true
empty($a) true
So we concluded:
1.is_null is only true for null and all others are false. In php, null is a variable that has neither type nor value. 2.isset is only false for null and the others are all t because '',' ', [], these three variables have clear data types, '' represents an empty string, ' ' represents a space string, [] represents an empty array. Therefore, a variable is true as long as it has type isset. 3.empty is false only for non-empty arrays and strings.The above is the detailed content of Introduction to the functions is_null, isset, empty in php. For more information, please follow other related articles on the PHP Chinese website!