Home > php教程 > php手册 > empty 和 isset 区别,emptyisset区别

empty 和 isset 区别,emptyisset区别

WBOY
Release: 2016-06-13 08:39:49
Original
898 people have browsed it

empty 和 isset 区别,emptyisset区别

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

<?<span>php

</span><span>/*</span><span>*
*    isset  &mdash; 检测变量是否设置
*    如果 变量 存在则返回 true, 否则返回 false
*
*    empty  &mdash; 检查一个变量是否为空
*    如果 变量 是非空或非零的值,则 empty() 返回 false
*</span><span>*/</span>

<span>$is_var</span> = ''<span>;

</span><span>if</span>(<span>isset</span>(<span>$is_var</span><span>)) {
    </span><span>echo</span> "变量存在!<br />"<span>;
} </span><span>else</span><span> {
    </span><span>echo</span> "变量不存在!<br />"<span>;
}

</span><span>if</span>(<span>empty</span>(<span>$is_var</span><span>)) {
    </span><span>echo</span> "变量为空!<br />"<span>;
} </span><span>else</span><span> {
    </span><span>echo</span> "变量不为空!<br />"<span>;
}

</span>?>
Copy after login

 输出结果:

变量存在!
变量为空!

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