通过php中的POST具有相同名称的多个输入 [英] Multiple inputs with same name through POST in php

查看:43
本文介绍了通过php中的POST具有相同名称的多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取多个相同名称的输入来发布,然后从 PHP 访问它们?这个想法是这样的:我有一个表格,允许输入不定数量的物理地址以及其他信息.如果我只是在多个条目中为这些字段中的每一个赋予相同的名称并通过 post 提交该数据,PHP 是否能够访问它?

例如,我在一个名为xyz"的页面上有五个输入,我想使用 PHP 访问它们.我可以这样做吗:

 $_POST['xyz'][0]

如果是这样,那将使我的生活轻松十倍,因为我可以通过表单发送无限量的信息,并通过简单地遍历名为xyz"的项目数组来让服务器对其进行处理.

解决方案

更改输入的名称:

然后:

$_POST['xyz'][0] == 'Lorem'$_POST['xyz'][4] == 'amet'

<小时><块引用>

如果是这样,那会让我的生活轻松十倍,因为我可以发送一个通过表格获取无限量的信息并对其进行处理由服务器简单地通过使用命名为xyz".

请注意,这可能是错误的解决方案.显然,这取决于您发送的数据.

Is it possible to get multiple inputs of the same name to post and then access them from PHP? The idea is this: I have a form that allows the entry of an indefinite number of physical addresses along with other information. If I simply gave each of those fields the same name across several entries and submitted that data through post, would PHP be able to access it?

Say, for example, I have five input on one page named "xyz" and I want to access them using PHP. Could I do something like:

    $_POST['xyz'][0]

If so, that would make my life ten times easier, as I could send an indefinite amount of information through a form and get it processed by the server simply by looping through the array of items with the name "xyz".

解决方案

Change the names of your inputs:

<input name="xyz[]" value="Lorem" />
<input name="xyz[]" value="ipsum"  />
<input name="xyz[]" value="dolor" />
<input name="xyz[]" value="sit" />
<input name="xyz[]" value="amet" />

Then:

$_POST['xyz'][0] == 'Lorem'
$_POST['xyz'][4] == 'amet'


If so, that would make my life ten times easier, as I could send an indefinite amount of information through a form and get it processed by the server simply by looping through the array of items with the name "xyz".

Note that this is probably the wrong solution. Obviously, it depends on the data you are sending.

这篇关于通过php中的POST具有相同名称的多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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