Question

I have a single variable with multiple values eg: domain.com/index.php?cat=1&cat=2&cat=3

When I use $_GET[cat] it will only get the last value '3'

How do I get all the values? Is it possible to then convert this result into a string:

eg: 1,2,3

Thanks

Was it helpful?

Solution

You need to use PHP array syntax to accomplish this:

domain.com/index.php?cat[]=1&cat[]=2&cat[]=3

Then in PHP:

$cats = implode(',', $_GET['cat']);
echo $cats; // 1,2,3

OTHER TIPS

In PHP you have to add brackets to make your variable an array

domain.com/index.php?cat[]=1&cat[]=2&cat[]=3

Then in PHP

echo $_GET['cat'][0]; // Outputs 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top