如何获得PHP $ _GET数组? [英] How to get PHP $_GET array?
问题描述
是否可以在$_GET
中将值作为数组?
Is it possible to have a value in $_GET
as an array?
如果我尝试发送与http://link/foo.php?id=1&id=2&id=3
的链接,并且我想在php端使用$_GET['id']
,那么该值怎么能成为数组?因为现在echo $_GET['id']
返回3
.它是标题链接中的最后一个ID.有什么建议吗?
If I am trying to send a link with http://link/foo.php?id=1&id=2&id=3
, and I want to use $_GET['id']
on the php side, how can that value be an array? Because right now echo $_GET['id']
is returning 3
. Its the last id which is in the header link. Any suggestions?
推荐答案
在PHP中执行此操作的通常方法是将id[]
放在URL中,而不只是id
:
The usual way to do this in PHP is to put id[]
in your URL instead of just id
:
http://link/foo.php?id[]=1&id[]=2&id[]=3
然后$_GET['id']
将是这些值的数组.它不是特别漂亮,但是可以直接使用.
Then $_GET['id']
will be an array of those values. It's not especially pretty, but it works out of the box.
这篇关于如何获得PHP $ _GET数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!