Answer the question
In order to leave comments, you need to log in
How to match any value in an array in PHP?
I am checking the cookie against a certain value. I would like to compare with an array of values and if there is at least one match, output data.
if(isset($_COOKIE[utm_campaign]) && $_COOKIE[utm_campaign] == $town) {
echo 'есть совпадение';
}
Answer the question
In order to leave comments, you need to log in
$arr = ['town', 'saun', 'babun'];
if (in_array($_COOKIE[utm_campaign], $arr)) {
// Истина где-то рядом
}
$towns = ['moscow','kiev','minsk'];
if(!empty($_COOKIE['utm_campaign']) && in_array($_COOKIE['utm_campaign'], $towns)) {
// ... your code here
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question