Home  >  Article  >  Backend Development  >  PHP determines whether it is an empty string

PHP determines whether it is an empty string

尚
Original
2019-10-29 13:24:099631browse

PHP determines whether it is an empty string

Method 1: Use $_MODULE['variable name']

if($_MODULE['var']) {
     // 这是表示已经输入了值
}
 
else {
     // 这里表示未输入值
}

Method 2: Assign the value first, and then use empty to judge.

Note: Any uninitialized variable, a variable with a value of 0 or false or an empty string "" or null, an empty array, or an object without any attributes will be judged as empty==true

Note 1: Uninitialized variables can also be detected as "empty" by empty

Note 2: empty can only detect variables, not statements

$a = 0;
$b = '';
$c = array();
if (empty($a)) echo '$a 为空' . "";
if (empty($b)) echo '$b 为空' . "";
if (empty($c)) echo '$c 为空' . "";
if (empty($d)) echo '$d 为空' . "";

Recommendation:phpserver

The above is the detailed content of PHP determines whether it is an empty string. 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