1

I'm looking into what is the best way to pass multiple values for the same parameter name via URL in PHP and then get those results.

Example:

http://www.example.com?color=blue&color=red&color=green

For some reason all the answers I can find is for other programing languages...

3
  • 1
    You'd have to "pack", eg. like ?color=red,green,blue and then explode it on the server side explode(',', $_GET['color']) Commented Dec 25, 2020 at 13:35
  • What is the standard? Doing that "pack" or pass them as array like the Ashu example? Commented Dec 25, 2020 at 13:48
  • Ashus approach is better in my opinion, because it's cleaner and uses the standarized, official way. Commented Dec 25, 2020 at 14:18

1 Answer 1

2

You can pass them as an array

 http://www.example.com?color[]=blue&color[]=red&color[]=green

On server side use $_GET['color'], which should return an array

print_r($_GET['color']); // Array ( [0] => green [1] => red [2] => blue )
Sign up to request clarification or add additional context in comments.

1 Comment

Sounds great, I think this solves my problem. Side question Is it also possible to make this type of url seo friendly like example.com/colors/blue/red/green via .htaccess?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.