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

有帮助吗?

解决方案

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

其他提示

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top