How does php determine whether a variable is null or not
This article introduces the relevant knowledge of "php how to judge whether a variable is null". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
PHP determines whether the variable is null
1. Is_null and isset
Both of these functions can determine whether a variable is null or not, and they agree with the empty string, zero false.
Is_null =! isset ()
The difference is that isset is a grammatical structure and is_null is a function. In terms of performance, the grammatical structure is relatively good. Therefore, isset is recommended instead of is_null in many places.
2, = and =
In some cases, it is recommended to use isset to determine whether a variable is null
But syntactically, a variable "whether initialization has been shown" and "whether it is null" is a different concept, and it is not appropriate to use isset in some scenarios, such as checking whether the return value of a function is null.
At this point, you can use "=" and "= =" to determine whether they are null.
For "=" and "= =", there is a big direct difference between them. For "= =", it recognizes the empty string, and 0 _ false is Null. For "= =", it represents null only if one variable is really null.
In addition, the performance of "=" is better than isset.
3. Just use "= =" to determine whether a variable is null or not.
4. Empty determines whether the content stored in a variable is zero or empty. 0, "0", null, false, array (), var $var, and objects without any attributes are considered empty and represent zero.
If $an is undefined or the value is NULLL,$a=NULL, it must be empty, that is, empty ($a) = true; if $an is of type int, $aq0, relative to the number, 0 represents zero, that is, empty ($a) = true
If $an is of type string, $a = "", relative to the string, "" means empty, that is, empty ($a) = true;. If $an is of type string, $a = "0", relative to the string, "0" represents zero, that is, empty ($a) = true.
If $an is of type bool and $a=false, the relative true,false represents null, that is, empty ($a) = true; if $an is of type array, $a=array (), relative to the array, the data without elements is empty, that is, empty ($a) = true.
This is the end of the content of "how php determines whether a variable is null". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!