In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what's the difference between empty () and isset () in PHP". The explanation in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "what's the difference between empty () and isset () in PHP?"
What the two have in common
Can determine whether a variable is empty or not
All return the boolean type, that is, true or false.
The difference between the two
The empty () function is used to check whether a variable is empty. When a variable does not exist, or when its value is equal to FALSE, then it is considered nonexistent. Empty () does not generate a warning if the variable does not exist.
The isset () function is used to detect whether the variable is set and is not NULL. If you have already freed a variable using unset (), the isset () judgment will return FALSE. If you use isset () to test a variable that is set to NULL, it returns FALSE. Also note that the null character ("\ 0") is not the same as the NULL constant of PHP.
For the judgment of 0, false, empty string, empty array, empty () can be recognized as empty, isset () can not.
1. Judgment of unset variables / / judgment of unset variables if (empty ($a)) {echo "empty: variable is empty". "
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is not set or variable is empty 2, judgment for" (empty string) / / judgment for "(empty string) $a ="; if (empty ($a)) {echo "empty: variable is empty". "
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is set and not empty 3, judgment for 0 (0 as integer) / / judgment for 0 (0 as integer) $a = 0 if (empty ($a)) {echo" empty: variable is empty "."
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is set and not empty 4, judgment for 0.0 (as 0 of floating point number) / / judgment for 0.0 (as 0 of floating point number) $a = 0.0scape if (empty ($a)) {echo" empty: variable is empty "."
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is set and not empty 5, judgment for" 0 "(as 0 of string) $a =" 0 "for" 0 "(as 0 of string); if (empty ($a)) {echo" empty: variable is empty. "
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is set and not empty 6, judgment for NULL / / judgment for NULL $a = null;if (empty ($a)) {echo" empty: variable is empty "."
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is not set or variable is empty 7, judgment for FALSE / / judgment for FALSE $a = false;if (empty ($a)) {echo" empty: variable is empty "."
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: variable is empty isset: variable is set and not empty 8, judgment for array () (an empty array) / / judgment for array () (an empty array) $a = array (); if (empty ($a)) {echo" empty: variable is empty "."
";} else {echo" empty: variable is not empty "."
";} if (isset ($a)) {echo" isset: variable is set and is not empty "."
";} else {echo" isset: variable is not set or is empty "."
";} # # result empty: the variable is empty isset: the variable has been set and is not empty. Thank you for reading. The above is the content of" what is the difference between empty () and isset () in PHP? "after the study of this article, I believe you have a deeper understanding of the difference between empty () and isset () in PHP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.