Description of the PHP empty () function

Source: Internet
Author: User
This article mainly introduces the description of the PHP empty () function, has a certain reference value, now share to everyone, the need for friends can refer to

On the face of it, it is easy to misunderstand that the empty () function is a function that determines whether a string is empty, in fact it is not, I eat a lot of losses.
The empty () function is used to test whether a variable has been configured. Returns False if the variable already exists, a non-empty string, or nonzero, and returns a true value. So, when the value of the string is 0 o'clock, it also returns True, which is the statement inside the empty. This is the trap.
such as: suppose $value = 0; Then empty ($value) =false.
Advise everyone, be careful to use the empty () function.
Judging if the string is empty, you can say so: if ($value = = "") ...
* Format: BOOL empty (mixed Var)
* Function: Check if a variable is empty
* Return value:
* Returns TRUE if the variable does not exist
* If the variable exists and its value is "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties, the TURE is returned.
* If the variable exists and the value is not "", 0, "0", NULL, FALSE, Array (), Var $var; And an object that does not have any properties, it returns FALSE
* Version: PHP 3, PHP 4, PHP 5
On the face of it, it is easy to misunderstand that the empty () function is a function that determines whether a string is empty, in fact it is not, I eat a lot of losses. The empty () function is used to test whether a variable has been configured. Returns False if the variable already exists, a non-empty string, or nonzero, and returns a true value. So, when the value of the string is 0 o'clock, it also returns True, which is the statement inside the empty. This is the trap. such as: suppose $value = 0; Then empty ($value) =false. Advise everyone, be careful to use the empty () function. Judging if the string is empty, you can say so: if ($value = = "") ... Format: bool Empty (mixed Var) function: Checks whether a variable is a null return value: Returns TRUE if the variable does not exist if the variable exists and its value is "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties, return TURE if the variable exists and the value is not "", 0, "0", NULL, FALSE, Array (), Var $var; and an object without any attributes, it returns 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 > No pictures </font></td>     </tr> <?} else {?>     <tr>       <td align= "Center "><font color=" Red "> Directory with pictures </font></td>     </tr> <?}?> </table>

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.