Page 1 of 1
Syntax question
Posted: Tue Jul 20, 2004 5:28 pm
by Xelmepa
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.
Posted: Tue Jul 20, 2004 5:39 pm
by feyd
Code: Select all
$valid_values = array('this','that');
if(in_array($$var, $valid_values))
//.......
Posted: Wed Jul 21, 2004 9:10 am
by Xelmepa
I was thinking of something using || actually.
But thanks anyway.
Posted: Wed Jul 21, 2004 9:38 am
by liljester
like this?
Code: Select all
if(($user_var != "this") && ($user_var != "that")){
//unaccecptable var
}
Posted: Wed Jul 21, 2004 10:54 am
by Xelmepa
Precisely. Thank you, sir.
Posted: Wed Jul 21, 2004 11:26 am
by John Cartwright
feyd wrote:Code: Select all
$valid_values = array('this','that');
if(in_array($$var, $valid_values))
//.......
what's wrong with this?
its easier to read and modify