Home > Backend Development > PHP Problem > What does empty mean in php?

What does empty mean in php?

青灯夜游
Release: 2023-02-27 14:00:01
Original
6805 people have browsed it

What does empty mean in php?

#What does empty mean in php?

empty means empty, it is a built-in function in php, used to check whether a variable is empty.

empty() Determines whether a variable is considered empty. When a variable does not exist, or its value is equal to FALSE, then it is considered not to exist. empty() does not generate a warning if the variable does not exist.

empty() After version 5.5, it supports expressions, not just variables.

Version requirements: PHP 4, PHP 5, PHP 7

Basic syntax:

empty ( $var )
Copy after login

Parameters: empty() The function accepts a single argument, as shown in the syntax above, as described below.

$ var: Variable used to check if it is empty.

Return value: Return false when $var exists and has a non-null non-zero value. Otherwise return true.

Note: Under PHP 5.5, the empty() function only supports variable checking, and anything else will cause a parsing error.

Simple example of empty() function

Let’s use an example to introduce how the empty() function uses to determine whether a variable is empty

<?php 
header("content-type:text/html;charset=utf-8");
echo "<br>";
$var1 = NULL; 
$var2 = ""; 
$var3 = "PHP中文网"; 
empty($var1) ? print_r("变量var1为空<br>") : print_r("变量var1不为空<br>"); 
  
empty($var2) ? print_r("变量var2为空<br>") : print_r("变量var2不为空<br>"); 
empty($var3) ? print_r("变量var3为空<br>") : print_r("变量var2不为空,值为:".$var3); 
?>
Copy after login

Output:

What does empty mean in php?

Explanation:

The following will be used by the empty() function Values ​​considered null:

1, "" (empty string)

2, 0 (0 as an integer)

3, 0.0 (0 as a floating point number )

4, "0" (0 as a string)

5, null

6, false

7, array() (an empty Array)

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of What does empty mean in php?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template