Why do I need the isset() function in php?

if-statement, isset, php, post

Solution

Because

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

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

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

(See also http://hk.php.net/manual/en/function.isset.php and http://hk.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting)

Problem

I am trying to understand the difference between this: ``` if (isset($_POST['Submit'])) { //do something } ``` and ``` if ($_POST['Submit']) { //do something } ``` 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?

Original source

Related problems