问题描述
我正在尝试使用相同的名称创建多个文本框.
这是我的代码.
I'm trying to do a multiple textbox with the same names.
Here is my code.
HTML
Email 1:<input name="email" type="text"><br>
Email 2:<input name="email" type="text"><br>
Email 3:<input name="email" type="text"><br>
PHP
$email = $_POST['email'];
echo $email;
我想得到这样的结果:
email1 @ email.com,email2 @ email.com,email3 @ email.com
我怎样才能做到这一点?有可能吗?
I wanted to have a results like this:
[email protected], [email protected], [email protected]
How can I do that? is that possible?
推荐答案
在元素名称中使用[]
Email 1:<input name="email[]" type="text"><br>
Email 2:<input name="email[]" type="text"><br>
Email 3:<input name="email[]" type="text"><br>
将在PHP端返回一个数组:
will return an array on the PHP end:
$email = $_POST['email'];
您可以implode()
以获得所需的结果:
you can implode()
that to get the result you want:
echo implode(", ", $email); // Will output [email protected], [email protected] ...
在对它们进行任何处理之前,例如,不要忘记对它们进行消毒.序列化数组或将它们插入数据库!仅仅因为它们位于数组中并不意味着它们是安全的.
Don't forget to sanitize these values before doing anything with them, e.g. serializing the array or inserting them into a database! Just because they're in an array doesn't mean they are safe.
这篇关于PHP $ _POST获取数据数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!