Skip to content
Advertisement

Check if URL parameter exist in comma separated values in php [closed]

I want to check if URL parameter exist from a series of comma seprated values. I have some code for this, that is,

$matchFound = (isset($_GET["id"]) && trim($_GET["id"]) == $urlval);
$slide = $matchFound ? trim($_GET["id"]) : '';

Now if $urlval = 12 and my URL is this- example website.com/test/?id=12 then the above code is working perfectly. But I want a code that can work even if $urlval = 10,11,12,13 and URL is- website.com/test/?id=12

Advertisement

Answer

just explode() your $urlval and use in_array() – this will work even when $urlval is a single value

$matchFound = isset($_GET["id"]) && in_array($_GET["id"], explode(",",$urlval));
$slide = $matchFound ? trim($_GET["id"]) : '';
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement