array_key_exists('submit_input_name',$ _ POST)是否优于($ _POST ["MM_insert"] =="submit_input_name") [英] Is array_key_exists('submit_input_name',$_POST) better than ($_POST["MM_insert"] == "submit_input_name")

查看:90
本文介绍了array_key_exists('submit_input_name',$ _ POST)是否优于($ _POST ["MM_insert"] =="submit_input_name")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经掌握了MySQL和HTML,但仍在学习PHP.我的时间表有点紧,所以 当我发现Dreamweaver会为我编写PHP时,我开始使用该功能.我立即注意到,当然,它所插入的代码并不是那么好.

I've got a handle on MySQL and HTML, but am still learning PHP. I'm on a bit of a schedule, so when I noticed that Dreamweaver would write PHP for me I started using that feature. I immediately noticed that, of course, the code it inserts isn't that great.

当调查通知:未定义的索引:"时,我遇到了 PHP错误:注意:未定义的索引:.

When investigating "Notice: Undefined index:" I came across PHP error: Notice: Undefined index:.

DeaconDesperado指出alibenmessaoud的代码正在尝试在设置post值之前进行处理.因此,我在代码中查看了同样的问题,并发现Dreamweaver正在使用

DeaconDesperado pointed out that alibenmessaoud's code was trying to process before post values were set. So I looked into my code for the same problem and noticed that Dreamweaver is using

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "name_of_your_submit_input"))

代替

if(isset($_POST) && array_key_exists('name_of_your_submit_input',$_POST))

我误解了Dreamweaver的代码吗?不检查帖子是否为提交名称与检查帖子是否存在相同吗?我是否误解了array_key_exists()?最后一个问题,我的支票在表格上方是否重要?

Am I misunderstanding Dreamweaver's code? Isn't checking if the post is the submit name the same as checking if it exists? Am I misunderstanding array_key_exists()? Last question, does it matter that my check is above the form itself?

感谢您接受尚未完成w3schools PHP教程的新手.

Thanks for putting up with a newbie who hasn't finished the w3schools PHP tutorial yet.

推荐答案

您给出的两个示例做的不是相同的事情,因此都不是更好的选择.

The two examples you've given don't do the same thing, therefore neither is better.

您的第一个示例询问$_POST中是否存在键MM_insert,其值是name_of_your_submit_input.

Your first example is asking whether key MM_insert exists in $_POST and that it's value is name_of_your_submit_input.

第二个例子是询问键name_of_your_submit_input是否存在,它也可能像这样:

Whereas your second example is asking whether the key name_of_your_submit_input exists, which could also look like this:

if (isset($_POST["name_of_your_submit_input"]))

无论如何,两个示例都不会引起该PHP通知.

In any case, both examples wouldn't cause that PHP Notice.

这篇关于array_key_exists('submit_input_name',$ _ POST)是否优于($ _POST ["MM_insert"] =="submit_input_name")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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