Home >Backend Development >PHP Tutorial >Description of PHP empty() function
This article mainly introduces the description of the PHP empty() function, which has certain reference value. Now I share it with you. Friends in need can refer to it
On the surface, it is easy to misunderstand The empty() function is a function that determines whether a string is empty. In fact, it is not, and I suffered a lot because of it.
The empty() function is used to test whether the variable has been configured. If the variable already exists, is a non-empty string, or is non-zero, a false value is returned; otherwise, a true value is returned. Therefore, when the value of the string is 0, true is also returned, which is to execute the statement inside empty. This is the trap.
For example: Assume $value = 0; then empty($value)=false.
I advise everyone to pay attention to using the empty() function.
To determine whether a string is empty, you can determine it like this: if ($value=="") ...
* Format: bool empty (mixed var)
* Function: Check whether a variable is empty
* Return value:
* If the variable does not exist, it returns TRUE
* If the variable exists and its value is "", 0, "0", NULL,, FALSE, array(), var $var ; and objects without any attributes, return TURE
* If the variable exists and the value is not "", 0, "0", NULL,, FALSE, array(), var $var; and objects without any attributes , then return FALSE
* Version: PHP 3, PHP 4, PHP 5
On the surface, it is easy to misunderstand that the empty() function is a function to determine whether the string is empty. In fact, it is not, and I also think so. Thanks a lot for eating. The empty() function is used to test whether the variable has been configured. If the variable already exists, is a non-empty string, or is non-zero, a false value is returned; otherwise, a true value is returned. Therefore, when the value of the string is 0, true is also returned, which is to execute the statement inside empty. This is the trap. For example: Assume $value = 0; then empty($value)=false. I advise everyone to be careful about using the empty() function. To determine whether a string is empty, you can do this: if ($value=="") ... Format: bool empty (mixed var) Function: Check whether a variable is empty Return value: If the variable does not exist, return TRUE If If the variable exists and its value is "", 0, "0", NULL,, FALSE, array(), var $var; and an object without any attributes, TRUE is returned. If the variable exists and its value is not "", 0, "0", NULL, FALSE, array(), var $var; and objects without any attributes, return FALSE Version: PHP 3, PHP 4, PHP 5
<table width="760" border="1" align="center" cellpadding="3"> <? $dir = './201006/24/'; $object[] = @readdir($dir); foreach ($object as $dirail) if (empty($dirail)) { ?> <tr> <td align="center"><font color="red">目录下没有图片</font></td> </tr> <? } else { ?> <tr> <td align="center"><font color="red">目录下有图片</font></td> </tr> <? } ?> </table>
The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
The above is the detailed content of Description of PHP empty() function. For more information, please follow other related articles on the PHP Chinese website!