Home  >  Article  >  Backend Development  >  什么情况下可以接受两个相同的key

什么情况下可以接受两个相同的key

WBOY
WBOYOriginal
2016-06-23 13:40:011086browse



如图,提交两组相同的key,提交后前台页面两组数据都显示出来了


回复讨论(解决方案)

<input name="userfile[]" type="text">

<input name="userfile[]" type="text">


知道这种方法是可以,但我看别人是没有[]这个的,

除了 php,其他服务器端语言都没有要求传入的同名变量要以数组方式命名
所以数组方式命名并不是必须的
但是,既然 php 这样约定了,还是遵守的比较好
按 php 的约定,不以数组方式命名的变量将会后面的覆盖前面的

不过你也可以不让 php 替你解析传输的数据,而自己解析

$s = file_get_contents('php://input');

可能得到这样的字符串
userfile=1&userfile=2&userfile=3

你可用字符串函数自行编程解析

除了 php,其他服务器端语言都没有要求传入的同名变量要以数组方式命名
所以数组方式命名并不是必须的
但是,既然 php 这样约定了,还是遵守的比较好
按 php 的约定,不以数组方式命名的变量将会后面的覆盖前面的

不过你也可以不让 php 替你解析传输的数据,而自己解析

$s = file_get_contents('php://input');

可能得到这样的字符串
userfile=1&userfile=2&userfile=3

你可用字符串函数自行编程解析

谢谢,豁然开朗呀
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn