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?
Put all the ids into a variable called $ids and separate them with a ",":
Pass them like so:
Process them:
You could make
id
a series of comma-seperated values, like this:index.php?id=1,2,3&name=john
Then, within your PHP code, explode it into an array:
This will maintain brevity. The other (more commonly used with $_POST) method is to use array-style square-brackets:
index.php?id[]=1&id[]=2&id[]=3&name=john
But that clearly would be much more verbose.
See How do I create arrays in a HTML
<form>
? in the PHP and HTML FAQ.