What does empty mean in php?

WBOY
Release: 2023-03-15 14:44:01
Original
7356 people have browsed it

In PHP, empty means empty. It is a built-in function used to check whether a variable is empty. The syntax is "empty (mixed $var)"; when the variable does not exist or the value of the variable, etc. If used as false, the variable is judged to not exist and the empty() function will not generate a warning.

What does empty mean in php?

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What does empty mean in php

empty means empty. It is a built-in function in php that is 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.

Syntax

bool empty ( mixed $var )
Copy after login

Parameter description:

$var: Variable to be checked.

Note: Prior to PHP 5.5, empty() only supported variables; anything else would cause a parsing error. In other words, the following code will not work:

empty(trim($name))
Copy after login

Instead, you should use:

trim($name) == false
Copy after login

empty() without generating a warning, even if the variable does not exist. This means that empty() is essentially equivalent to !isset($var) || $var == false .

Return value

When var exists and is a non-empty and non-zero value, return FALSE otherwise return TRUE.

The following variables will be considered empty:

  • "" (empty string)

  • 0 (as 0 as an integer)

  • 0.0 (0 as a floating point number)

  • "0" (0 as a string)

  • NULL

  • ##FALSE

  • ##array() (an empty array)
  • $var; (a variable declared but without a value)
  • Recommended study: "
PHP Video Tutorial

"

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:
php
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