Home > php教程 > php手册 > empty 和 isset 区别 - jerrylsxu

empty 和 isset 区别 - jerrylsxu

WBOY
Release: 2016-05-20 09:33:47
Original
1272 people have browsed it

这两个函数一直不是很理解,写个小程序加深理解!

复制代码
<span style="color: #000000;">php

</span><span style="color: #008000;">/*</span><span style="color: #008000;">*
*    isset  — 检测变量是否设置
*    如果 变量 存在则返回 true, 否则返回 false
*
*    empty  — 检查一个变量是否为空
*    如果 变量 是非空或非零的值,则 empty() 返回 false
*</span><span style="color: #008000;">*/</span>

<span style="color: #800080;">$is_var</span> = ''<span style="color: #000000;">;

</span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$is_var</span><span style="color: #000000;">)) {
    </span><span style="color: #0000ff;">echo</span> "变量存在!<br>"<span style="color: #000000;">;
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
    </span><span style="color: #0000ff;">echo</span> "变量不存在!<br>"<span style="color: #000000;">;
}

</span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$is_var</span><span style="color: #000000;">)) {
    </span><span style="color: #0000ff;">echo</span> "变量为空!<br>"<span style="color: #000000;">;
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
    </span><span style="color: #0000ff;">echo</span> "变量不为空!<br>"<span style="color: #000000;">;
}

</span>?>
Copy after login
复制代码

 输出结果:

变量存在!
变量为空!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template