Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between null and empty in php

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what are the differences between null and empty in php", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the difference between null and empty in php".

The difference between null and empty in php: empty is a function that checks whether a variable is empty, true; is returned if the variable is empty, and null is a data type, indicating that a variable has no value that is empty, and is represented as null when the variable is assigned to mull, not assigned, or by unset ().

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

What is the difference between null and empty in php

Null means that a variable has no value. There are three cases in which a variable is null:

1. Is assigned to NULL.

two。 Has not been assigned yet.

3. By unset ().

The empty () function is used to check whether a variable is empty.

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

Expressions, not just variables, are supported after empty () 5.5.

Grammar

Bool empty (mixed $var)

Parameter description:

Var: the 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 take effect:

Empty (trim ($name))

Instead, you should use:

Trim ($name) = = false

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

Returns FALSE if var exists and is a non-empty non-zero value. Otherwise, TRUE is returned.

The following variables are considered empty:

"" (empty string)

0 (0 as an integer)

0.0 (as 0 of a floating point number)

"0" (as 0 of the string)

NULL

FALSE

Array () (an empty array)

$var; (a variable that is declared but has no value)

Example

The above is about the content of this article on "what is the difference between null and empty in php?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report