In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "php how to judge whether the variable is null". In the daily operation, I believe that many people have doubts about how to judge whether the variable is null or not in php. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt that "php how to judge whether the variable is null". Next, please follow the editor to study!
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.
At this point, the study on "how php determines whether a variable is null or not" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.