PHP function completion: empty (). Empty () is used to check whether a variable is empty. If the variable is not null or a non-zero value, empty () returns FALSE. In other words, 0, 0, NULL, FALSE, array (), about empty ()
Empty () is used to check whether a variable is empty. If the variable is not null or a non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.
A simple comparison between empty () and isset.
Because this is a language structure rather than a function, it cannot be called by variable functions.
Empty () only detects variables, and any non-variables will cause parsing errors. In other words, the following statement does not work: empty (addslashes ($ name )).
Empty checks whether a variable is "null", and isset checks whether a variable has been set. This so-called "name implies" makes me take some detours at the beginning: When a variable value is equal to 0, empty () will also be True ), as a result, some accidents may occur. Originally, although empty and isset are both variable processing functions, they are used to determine whether the variables have been configured, but they are different: empty also checks whether the variables are empty and zero. When the value of a variable is 0, empty considers this variable to be null, that is, it is equivalent to not being set.
For example, if the $ id variable is detected and $ id = 0, empty and isset are used to check whether the variable $ id has been configured. different values will be returned for both -- empty considers no configuration, isset can get the value of $ id:
Test Code
";! Isset ($ id )? Print "It's empty.": the value of print '$ ID'. "is $ id.";?>
Program running result:
The variable $ id is empty.
The value of $ id is 0.
This means that when we use a variable to process a function, when the variable may have a value of 0, we should be careful when using empty. in this case, it is more wise to replace it with isset.
When the URL tail parameter of a php page shows id = 0 (for example, test. php? Id = 0), try to compare:
If (empty ($ id) $ id = 1; // if id = 0, the id is also 1if (! Isset ($ id) $ id = 1; // If id = 0, id will not be 1
Run the following code separately to detect the above inference:
If (empty ($ id) $ id = 1; print $ id; // Get 1
If (! Isset ($ id) $ id = 1; print $ id; // get 0
Receivempty () empty () is used to check whether a variable is empty. If the variable is not null or a non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (),...