I have a user defined variable, but as values I only want to accept "this" or "that".
Which are the possible ways of doing that?
(I figure I can put an if inside another if, but that's not very inventive.)
Thank you.
Syntax question
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$valid_values = array('this','that');
if(in_array($$var, $valid_values))
//.......like this?
Code: Select all
if(($user_var != "this") && ($user_var != "that")){
//unaccecptable var
}- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
what's wrong with this?feyd wrote:Code: Select all
$valid_values = array('this','that'); if(in_array($$var, $valid_values)) //.......
its easier to read and modify