将数组从HTML表单传递给PHP [英] Passing arrays from HTML form to PHP

查看:103
本文介绍了将数组从HTML表单传递给PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是HTML:

This is the HTML:

<input type="text" name="shortcut[]" value="a"/> do <input type="text" name="ses[]" value="1" disabled/><br>
<input type="text" name="shortcut[]" value="b"/> do <input type="text" name="ses[]" value="2" disabled/><br>
<input type="text" name="shortcut[]" value="c"/> do <input type="text" name="ses[]" value="3" disabled/><br>

如何将值传递给PHP,但连接两个数组的索引?


ie
将数据库值1置入其中something = a,

置入数据库值2 where something = b

等等...

How do I pass the values to PHP but connect the indexes of both arrays?

i.e.
put in database value 1 where something = a,
put in database value 2 where something = b
and so on ...

推荐答案

索引是自动连接的,因为它们是数字数组。

The indexes are connected automatically, since they're numeric arrays.

$nvals = count($_REQUEST['shortcut']);
for ($i = 0; $i < $nvals; $i++) {
  // do something with $_REQUEST['shortcut'][$i] and $_REQUEST['ses'][$i]
}

这篇关于将数组从HTML表单传递给PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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