Home  >  Article  >  Backend Development  >  How to determine if a variable does not exist in php

How to determine if a variable does not exist in php

藏色散人
藏色散人Original
2021-03-08 09:44:512803browse

php method to determine whether a variable does not exist: 1. Use the isset method to detect whether the variable is set and not NULL; 2. Use empty to determine whether a variable is considered empty; 3. Use is_null to determine whether the variable exists. .

How to determine if a variable does not exist in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

How to determine whether a variable exists in php

Three methods for php to determine whether a variable exists:

1.bool isset (mixed var[,mixedvar [,mixed... ] )

Check whether the variable is set and not NULL.

If multiple parameters are passed in at one time, isset() will only return TRUE when all parameters are set. The calculation process is from left to right and will stop immediately when encountering an unset variable.

2. bool empty (mixed $var)

Determine whether a variable is considered empty.

The following things are considered empty:

"" (空字符串)
0 (作为整数的0)
0.0 (作为浮点数的0)
"0" (作为字符串的0)
NULL
FALSE
array() (一个空数组)
$var; (一个声明了,但是没有值的变量)

3. Insert code snippet here bool is_null (mixed $var)

The NULL type has only one value, which is not The case-sensitive constant NULL.

The above is the detailed method of how PHP determines whether a variable exists.

[Recommended: "PHP Video Tutorial"]

The above is the detailed content of How to determine if a variable does not exist 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