faya faya - 1 month ago 6
PHP Question

How to get PHP $_GET array?

Is it possible to have a value in

$_GET
as an array?

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?

Answer

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

Then $_GET['id'] will be an array of those values. It's not especially pretty, but it works out of the box.