Link to home
Start Free TrialLog in
Avatar of dsrnu
dsrnu

asked on

How can I improve this if then statement?

Basically I'm trying to remove the "else" in this statement.. Any ideas?

if ($type == 'fan' OR $type == 'artist')
{
	// ok
}
else
{ // Not a valid value!
	redirect('');
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of numberkruncher
numberkruncher
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Depending upon how your redirect logic works, you might want to kill execution.
if (! ($type == 'fan' OR $type == 'artist') ) {
   redirect('');
   // Make sure that nothing gets past this line!
   die;
}

// ok

Open in new window

Avatar of dsrnu
dsrnu

ASKER

Will return work just as well as die?
Avatar of gamebits
if ($type != 'fan' OR $type != 'artist')
{
  redirect('');
}
die will kill the script, return will break from the function / script.
think of die as "End Program"
@gamebits:

I may be wrong, but wouldn't it be:
if ($type != 'fan' AND $type != 'artist')

Open in new window

@numberkruncher

yep.