我可以使用相同的键,不同的值来使用多个$ _GET吗?

d-_*_*_-b 8 php get

是否可以从相同$ _GET具有不同值的url中检索参数?

www.domain.com/?user=1&user=2

目前这只显示第二个列出的内容,所以如果我echo $_GET['user'],它会输出2

我似乎无法在SO上找到这个,所以如果我错过了,请告诉我.

谢谢你的帮助!

Vjy*_*Vjy 9

是的,使用user []作为密钥.应该管用.PHP将所有$ _POST []变量访问到一个数组中?


Kah*_*eng 5

快速回答是否定的。

http://localhost/?user=1&user=2
Run Code Online (Sandbox Code Playgroud)

让你:

array
    'user' => string '2' (length=1)
Run Code Online (Sandbox Code Playgroud)

但是,通过在查询中包含括号,如下所示:

http://localhost/?user[]=1&user[]=2
Run Code Online (Sandbox Code Playgroud)

您可以检索 $_GET['user'] 并返回以下内容:

array
    'user' => 
        array
            0 => string '1' (length=1)
            1 => string '2' (length=1)
Run Code Online (Sandbox Code Playgroud)