是否可以将表单字段值放入数组中?示例:
<?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/