C
C
CrewCut2015-12-10 13:55:23
PHP
CrewCut, 2015-12-10 13:55:23

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 'есть совпадение';
}

$town is now a string, I would like an array. How to check this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
D', 2015-12-10
@CrewCut

$arr = ['town', 'saun', 'babun'];
if (in_array($_COOKIE[utm_campaign], $arr)) {
  // Истина где-то рядом
}

S
Stalker_RED, 2015-12-10
@Stalker_RED

$towns = ['moscow','kiev','minsk'];

if(!empty($_COOKIE['utm_campaign']) && in_array($_COOKIE['utm_campaign'], $towns)) {
  // ... your code here
}

A
Alexander, 2015-12-10
@disc

Try the in_array() method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question