Page 1 of 1

Checking a value within a list

Posted: Fri Dec 02, 2005 9:40 am
by hame22
Hi

I am looking for a way in which I can check a variable is in a certain list of values.

What i am doing is taking a country then checkin whether it is in a certain group e.g. continent etc.

Now i know i can do this:

Code: Select all

if ($cn = UK || $cn = SP || $cn = FR || $cn =GER || ..etc.....

print ' European country';

but i wondered whether there is a quicker way to achieve this in code

Thanks in advance

Posted: Fri Dec 02, 2005 10:01 am
by pickle
Put all country abbreviations in an array, then call in_array() to check:

Code: Select all

$eu = array("UK","SP","FR","SK");
if(in_array($cn,$eu))
{
   echo "European Country";
}

Posted: Fri Dec 02, 2005 10:13 am
by hame22
awesome exactly what i was after, thanks!!