Nicolas Racine
Nicolas Racine

Reputation: 1061

OR Condition check multiple values possible?

I have no idea what I m looking for is called so I m asking if there is a way in php to check if one of multiple hardcoded value are true

What I mean is, is it possible to write the following condition

if($var == 'this' || $var == 'orthis') //this can become very long

By writing something similar like the following

if($var == 'this'||'orthis') //skiping the "||$var == " every value i want to check

I know I could technically just write the following

if(in_array($var,array('this','orthis')))

But I am currious to know if there is something like the second line.

Thanks!

Upvotes: 0

Views: 41

Answers (2)

Wee Zel
Wee Zel

Reputation: 1324

you could also use a switch statement

switch ($var) {
case 'this':
case 'orthis':
  // some code
  break;
}

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

You're looking for a syntax like the in operator in SQL. But unfortunately for you there is no syntax for that, other than tricks like using in_array, like you suggested yourself.

Upvotes: 1

Related Questions