0

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!!!

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by kireol
1

also if you wanted it more VB style

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

Edited by kireol: n/a

Votes + Comments
This is a much better solution since it can be changed dynamically
0

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

Edited by kishan112: n/a

0

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" ; }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.