如何获取表单输入数组PHP数组 [英] How to get form input array into PHP array
问题描述
我有一个低于发布到contacts.php的一个形式,用户可以动态使用jQuery添加更多。
I have a form like the one below which is posted to contacts.php, and the user can dynamically add more with jquery.
<input type="text" name="name[]" />
<input type="text" name="email[]" />
<input type="text" name="name[]" />
<input type="text" name="email[]" />
<input type="text" name="name[]" />
<input type="text" name="email[]" />
如果我赞同出来与code PHP低于
If i echo them out in php with the code below
$name = $_POST['name'];
$email = $_POST['account'];
foreach( $name as $v ) {
print $v;
}
foreach( $name as $v ) {
print $v;
}
我会得到这样的事情
i will get something like this
name1name2name3email1email2email3
name1name2name3email1email2email3
我怎么可以让这些阵列弄成像code以下
how can i get those arrays into something like the code below
function show_Names($n, $m)
{
return("The name is $n and email is $m, thank you");
}
$a = array("name1", "name2", "name3");
$b = array("email1", "email2", "email3");
$c = array_map("show_Names", $a, $b);
print_r($c);
所以我的我的输出是这样的。
so my my output is like this
的名称是名1 和电子邮件 EMAIL1 ,谢谢结果
这个名字是名2 和电子邮件是 EMAIL2 ,谢谢结果
这个名字是 NAME3 和电子邮件是 EMAIL3 ,谢谢
The name is name1 and email is email1, thank you
The name is name2 and email is email2, thank you
The name is name3 and email is email3, thank you
感谢您的任何帮助或建议
thank you for any help or advice
推荐答案
他们已经在数组: $名称
是一个数组,如 $电子邮件
They are already in arrays: $name
is an array, as is $email
因此,所有你需要做的就是增加一点处理的攻击两个数组:
So all you need to do is add a bit of processing to attack both arrays:
$name = $_POST['name'];
$email = $_POST['account'];
foreach( $name as $key => $n ) {
print "The name is ".$n." and email is ".$email[$key].", thank you\n";
}
要处理更多的投入,只是延长模式:
To handle more inputs, just extend the pattern:
$name = $_POST['name'];
$email = $_POST['account'];
$location = $_POST['location'];
foreach( $name as $key => $n ) {
print "The name is ".$n.", email is ".$email[$key].
", and location is ".$location[$key].". Thank you\n";
}
这篇关于如何获取表单输入数组PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!