PHP determines whether it is an empty string

Release: 2023-02-27 22:26:01
Original
9643 people have browsed it

PHP determines whether it is an empty string

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

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

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 为空' . "";
Copy after login

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!

Related labels:
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