Back again!

I now need to check if a variable holds one of multiple values...I.E:

if ($cvalue  == "Germany" OR "England" OR "latvia" OR "Africa") { echo "Do something" ; }

In VB I'd just have used something like:

in("Germany" OR "England" OR "latvia" OR "Africa")

Any help appreciated...digging through my PHP docs as we speak, but cannot see the way!!!

Recommended Answers

All 6 Replies

also if you wanted it more VB style

$places = array("Germany", "England", "Latvia", "Africa");
if (in_array($cvalue, $places)) 
{
  echo "do something";
}
commented: This is a much better solution since it can be changed dynamically +1

This is how it's done

if ($cvalue  == "Germany" || $cvalue  ==  "England" || $cvalue  ==  "latvia" || $cvalue  ==  "Africa") { echo "Do something" ; }

Or you can use an array:

$countries = array("Germany","England","Latvia","Africa");
if (in_array($cvalue,$countries)) { echo "Do something" ; }

Remember that in_array() is case-sensitive

This is how it's done

if ($cvalue  == "Germany" || $cvalue  ==  "England" || $cvalue  ==  "latvia" || $cvalue  ==  "Africa") { echo "Do something" ; }

Or you can use an array:

$countries = array("Germany","England","Latvia","Africa");
if (in_array($cvalue,$countries)) { echo "Do something" ; }

Remember that in_array() is case-sensitive

true

$countries = array("GERMANY","ENGLAND","LATVIA","AFRICA");
if (in_array(strtoupper($cvalue),$countries)) { echo "Do something" ; }

yeah or

ucfirst(strtolower($cvalue)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.