I have a variable $var which must be either one or two and if it’s not then throw an error
if($var != "one" && $var != "two")
{
exit('$var must be either one or two');
}
This works. However as $var is a string and can only hold one value not both, so I’m wondering if it’s not logical to write like that?
That’s fine, the illogical code would be
($var == 'one' && $var == 'two')You are checking that it’s not one or two – a variable can ‘not be’ an endless amount of values.