Multiple inputs with same name through POST in php(通过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具有相同名称的多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过php中的POST具有相同名称的多个输入
基础教程推荐
- 使用 PDO 转义列名 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- HTTP 与 FTP 上传 2021-01-01