Syntax question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

Syntax question

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$valid_values = array('this','that');

if(in_array($$var, $valid_values))
//.......
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

Post by Xelmepa »

I was thinking of something using || actually.

But thanks anyway.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

like this?

Code: Select all

if(($user_var != "this") && ($user_var != "that")){
    //unaccecptable var
}
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

Post by Xelmepa »

Precisely. Thank you, sir.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply