Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Or logic problem...

Status
Not open for further replies.

jimoblak

Instructor
Oct 23, 2001
3,620
US
I would like to do an action if a variable exists in several different values - - without a lot of code.

A user on my site will be directed to a different action depending on what country they are from. Here is a sample of my present code:

if (($country=="AU") OR ($country=="CL") OR ($country=="NZ") OR ($country=="NI") OR ($country=="PA") OR ($country=="PH") OR ($country=="TT") OR ($country=="UM") OR ($country=="VI") OR ($country=="BR") OR ($country=="AR") OR ($country=="BS") OR ($country=="BB") OR ($country=="BM")) {
//then do this
}

Is there a simpler way of doing this without repeating so much code? I have a set of about 20 countries for each action (and there are several different action sets). To simplify the example above, I have not included all the countries I intend to use. The list will be much larger.

Thank you!
 
use this

$array=array("AU","CL",...);
if (in_array($country,$array)){
// then do this:
}

i think it's this the order of the params in the in_array function, but if it is not, just switch the order of them. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks for the help, xutopia & anikin!

I tried the array earlier but had a stupid syntax error that threw me way off and led me to Tek-Tips screaming for help.
 

<QUOTE>

...had a stupid syntax error that threw me way off and led me to Tek-Tips screaming for help...

</QUOTE>


Welcome to my world!!....;):)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top