0

Let's say I have the following URL:

http://www.site.com/index.php?size=40&size=60

If I display the $_GET array, the results looks like this:

Array
(
  [size] => 60
)

How can I look the $_GET array like this:

Array
(
  [size] => 40
  [size] => 60
)
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • An array can never have duplicates keys ever. – Rikesh Jan 25 '14 at 14:13
  • 2
    **don't** use the same variable multiple times in a URL. though it's technically valid, it's very bad practice. – Karoly Horvath Jan 25 '14 at 14:13
  • URL query should be like ?size[]=40&size[]=60 – Ed T. Jan 25 '14 at 14:13
  • possible duplicate of [How to get PHP $\_GET array?](http://stackoverflow.com/questions/1833330/how-to-get-php-get-array) – Fractaliste Jan 25 '14 at 14:13
  • It's not possible to do that. It does not make sense since, to acess it, you would need to specify one of them beeing them equal. I suggest you make the `[code]` key an array and, inside it, store that values as convenient. – D. Melo Jan 25 '14 at 14:14
  • It's an duplication : [link](http://stackoverflow.com/questions/7206978/how-to-pass-an-array-via-get-in-php) – R3tep Jan 25 '14 at 14:18

3 Answers3

4

Use this, the brackets, to put it in an array.

http://www.site.com/index.php?size[]=40&size[]=60

vincent kleine
  • 724
  • 1
  • 6
  • 22
0

You cannot have same keys for the $_GET superglobal array as well as any normal arrays.

Change the name of the parameters to different ones say size1 and size2.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

Maybe you want something like this:

URL:

http://www.site.com/index.php?size[]=40&size[]=60

PHP:

   foreach( $_GET["size"] as $size ){
        // Here manipulate each size    
    }

Of course if you want to use it all this for filters, try this:

http://www.site.com/index.php?size=40,60

and in php:

foreach( explode(',',$_GET["size"]) as $size ){
        // Here manipulate each size    
    }
Dimitris Bouzikas
  • 4,461
  • 3
  • 25
  • 33