문제

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