php - 在 PHP 中将表单值获取到数组中

标签 php

是否可以将表单字段值放入数组中?示例:

<?php
     array('one', 'two', 'three');
?>
<form method="post" action="test.php">
    <input type="hidden" name="test1" value="one" />
    <input type="hidden" name="test2" value="two" />
    <input type="hidden" name="test3" value="three" />
    <input type="submit" value="Test Me" />
</form>

在 PHP 中是否可以将所有表单值(无论其数量)传递给数组?

最佳答案

是的,只需将输入命名为相同的名称并在每个输入后放置方括号:

<form method="post" action="test.php">
    <input type="hidden" name="test[]" value="one" />
    <input type="hidden" name="test[]" value="two" />
    <input type="hidden" name="test[]" value="three" />
    <input type="submit" value="Test Me" />
</form>

然后你可以测试:

<?php
    print_r($_POST['test']);
?>

关于php - 在 PHP 中将表单值获取到数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1924324/

相关文章:

php - 这段代码对于 mysql 注入(inject)安全吗?

php - 通过 PayPal 和信用卡接收付款

php - php循环中的ajax在按钮单击时执行操作

php - 新的 Instagram API - 您如何请求标记的媒体?

php - 获取从复选框返回的真/假值,错误时出错

php - 是否可以将图像存储在用户的浏览器上

php - 上下文错误异常 : Notice: Undefined variable?

php - 在我的 query_posts 语句中使用 GET 是否不好? (WP)

php - Laravel : Passing extra parameter on Collection filtering

php - mysql 选择、计数、左连接和显示