如何将表单输入数组转换为PHP数组我有一个类似于下面的表单,它被发布到contacts.php,用户可以使用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[]" />如果我用下面的代码在php中回显它们$name = $_POST['name'];$email = $_POST['account'];foreach( $name as $v ) {print $v;}foreach( $email as $v ) {print $v;}我会得到这样的东西:name1name2name3email1email2email3如何将这些数组放入下面的代码中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);所以我的输出是这样的:名字是名1电子邮件是电邮1,谢谢名字是名称2电子邮件是电邮2,谢谢名字是名称3电子邮件是电邮3,谢谢谢谢你的帮助或建议
3 回答
莫回无
TA贡献1865条经验 获得超7个赞
$name
$email
$name = $_POST['name'];$email = $_POST['account'];foreach( $name as $key => $n ) { print "The name is ".$n." and email is ".$email[$key].", thank you\n";}
$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";}
千巷猫影
TA贡献1829条经验 获得超7个赞
<input type="text" name="item[0][name]" /><input type="text" name="item[0][email]" /><input type="text" name="item[1][name]" /> <input type="text" name="item[1][email]" /><input type="text" name="item[2][name]" /><input type="text" name="item[2][email]" />
function show_Names($e){ return "The name is $e[name] and email is $e[email], thank you";}$c = array_map("show_Names", $_POST['item']);print_r($c);
- 3 回答
- 0 关注
- 903 浏览
添加回答
举报
0/150
提交
取消