In php, there are many methods to judge whether a string is null, such as null, empty, and isset, which can be used to determine whether a variable or string is null, next I will introduce it to you. string; judge whether the string is null; output... there are many methods to judge whether a string is null in php, such as null = null, empty, and isset, which can be used to determine whether a variable or string is null, next I will introduce it to you.
String; judge whether the string is null; output judgment; you can modify it
The instance code is as follows:
If (emptyempty ($ C_char) return false; // whether if ($ C_char = '') return false has been set; // whether it is null
Use = ""
The instance code is as follows:
Empty determines whether it is null
The instance code is as follows:
On the surface, it is easy to misunderstand that the empty () function is a function used to judge whether the string is null. In fact, it is not, so I suffered a lot of losses.
The empty () function is used to test whether the variable has been configured. if the variable already exists, non-null string, or non-zero, false is returned; otherwise, true is returned. therefore, if the value of the string is 0, true is returned, that is, the internal statement of empty is executed. this is a trap. for example, suppose $ value = 0; then empty ($ value) = false.
To judge whether the string is null, you can judge it as follows: if ($ value = "")...
* Format: bool empty (mixed var)
* Function: check whether a variable is empty.
* Return value:
* Returns TRUE if the variable does not exist.
* If a variable exists and its values are "", 0, "0", NULL, FALSE, array (), var $ var, and objects without any attribute, true is returned.
* If a variable exists and its values are not "", 0, "0", NULL, FALSE, array (), var $ var, or an object without any attribute, FALSE is returned.
Isset () and empty () judgment methods:
The instance code is as follows:
"; If (isset ($ var) n {echo 'variable $ var exists!
';} Else {echo' variable $ var does not exist!
';} Echo "empty test:
"; If (emptyempty ($ var) {echo 'variable $ var value is empty
';} Else {echo' variable $ var value is not empty
';} Echo "variable direct test:
"; If ($ var) {echo 'variable $ var exists!
';} Else {echo' variable $ var does not exist!
';}}?>
Address:
Reprinted at will, but please attach the article address :-)