Description of PHP empty() function

不言
Release: 2023-04-02 12:16:01
Original
3285 people have browsed it

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

目录下没有图片
目录下有图片
Copy after login

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:

How to test memcached in PHP

Introduction to PHP Closure

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!