Empty to determine whether a variable is "empty", isset to determine whether a variable has been set. It is this so-called "as the name implies" that I began with some detours: when a variable value is equal to 0 o'clock, empty () will also be set (True), so there will be some surprises. Originally, empty and isset, although they are variable processing functions, they are used to determine whether the variable has been configured, they are a certain difference: empty will also detect whether the variable is empty, zero. When a variable value is 0,empty that the variable equals null, that is, the equivalent is not set. For example, detect $id variable, when $id=0, with empty and isset to detect whether the variable $id has been configured, both will return a different value--empty think there is no configuration, isset can obtain $id value: $id=0; Empty ($id) print "It's empty.":p rint "it ' $id."; Result: It ' s empty. print "<br>"; !isset ($id) print "It's empty.":p rint "it ' $id."; Result: It ' s 0. This means that when we use a variable-handling function, when the variable is likely to have a value of 0, use empty to be careful, and it's wiser to replace it with Isset. When a PHP page URL tail parameter appears id=0 (for example: test.php?id=0), try to compare: if (empty ($id)) $id=1; -If id=0, the ID will also be 1 if (!isset ($id)) $id=1; -if id=0, id not be 1 can run the following code to detect the above inference: if (empty ($id)) $id=1; Print $id; Get 1 if (!isset ($id)) $id=1; Print $id; Get 0
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service