Home  >  Article  >  Backend Development  >  The difference between empty and isset, the difference between emptyisset_PHP tutorial

The difference between empty and isset, the difference between emptyisset_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:19907browse

The difference between empty and isset, the difference between emptyisset

I have never understood these two functions very well. I will write a small program to deepen my understanding!

The difference between empty and isset, the difference between emptyisset_PHP tutorial
<?<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>?>
The difference between empty and isset, the difference between emptyisset_PHP tutorial

Output result:

Variable exists!
The variable is empty!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127594.htmlTechArticleThe difference between empty and isset, the difference between emptyisset and these two functions. I have never understood it very well. I will write a small program to deepen my understanding! ? php /* ** isset detects whether the variable is set* If the variable exists, return...
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