为什么我需要php中的isset()函数? [英] Why do I need the isset() function in php?

查看:139
本文介绍了为什么我需要php中的isset()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解它之间的区别:

I am trying to understand the difference between this:

if (isset($_POST['Submit'])) { 
  //do something
}

if ($_POST['Submit']) { 
  //do something
}

在我看来,如果$ _POST ['Submit']变量为true,则设置为。在这种情况下,为什么我需要isset()函数?

It seems to me that if the $_POST['Submit'] variable is true, then it is set. Why would I need the isset() function in this case?

推荐答案

因为

$a = array("x" => "0");

if ($a["x"])
  echo "This branch is not executed";

if (isset($a["x"]))
  echo "But this will";

(另见 http://hk.php.net/manual/en/function.isset.php http://hk.php.net/manual/en/language.types.boolean.php# language.types.boolean.casting

这篇关于为什么我需要php中的isset()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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