if(isset($ var))和if($ var)之间的区别 [英] Difference between if(isset($var)) and if($var)

查看:244
本文介绍了if(isset($ var))和if($ var)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
if(!Variable)和if(isset($ variable))之间有什么区别? ?

Possible Duplicate:
Whats the difference between if(!Variable) and if(isset($variable)) ?

在Facebook的php API示例中,他们使用if($ var){//做某事} else {//做其他事} ick使我开始思考if($ var)和if(isset($ var))的区别.第一个确定的对象看起来更整洁,但是我可以确定使用它吗?

In Facebooks php API example they use if($var){ //do something }else{ //do something else} whick got me thinking about the difference of if($var) and if(isset($var)). The first sure looks neater but can I surely use it?

推荐答案

使用

if ($var)

您将测试$var是否包含不为false的值-1为true,123也为false ...

You'll test if $var contains a value that's not false -- 1 is true, 123 is too, ...

有关被认为是假的更多信息,您应该查看

For more informations about what is considered as true or false, you should take a look at Converting to Boolean.


使用
isset() ,您将测试是否已设置变量-即是否未设置任何变量-null值已写入其中.


Using isset(), you'll test if a variable has been set -- i.e. if any not-null value has been written to it.

这篇关于if(isset($ var))和if($ var)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆