Home  >  Article  >  Backend Development  >  How to determine whether a variable is empty in php

How to determine whether a variable is empty in php

王林
王林Original
2020-08-05 15:02:264282browse

How to determine whether a variable is empty in php: You can use the isset() function to determine. The isset() function is used to detect whether a variable has been set and is not NULL. If a variable has been released using the unset() function, it will return FALSE through the isset() function.

How to determine whether a variable is empty in php

isset() function is used to detect whether the variable has been set and is not NULL.

(Recommended tutorial: php graphic tutorial)

If you have used unset() to release a variable, and then pass isset() to judge, it will return FALSE. If you use isset() to test a variable that is set to NULL, it will return FALSE.

Also note that the null character ("\0") is not equivalent to PHP's NULL constant.

Syntax:

bool isset ( mixed $var [, mixed $... ] )

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 no setting is encountered halfway. variable will stop immediately.

(Video tutorial recommendation: php video tutorial)

Return value:

If the specified variable exists and is not NULL, return TRUE, otherwise Return FALSE.

Code example:

Output result:

变量已设置。
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)

The above is the detailed content of How to determine whether a variable is empty 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