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

后端 未结 6 1684
终归单人心
终归单人心 2021-01-04 06:27

I am trying to understand the difference between this:

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

and

if ($_POST[         


        
6条回答
  •  感情败类
    2021-01-04 07:11

    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)

提交回复
热议问题