search
HomeBackend DevelopmentPHP ProblemWhat does empty mean in php?

What does empty mean in php?

Oct 19, 2019 pm 06:08 PM
emptyphp

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 )

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); 
?>

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor