I want to check if a variable is equal to b or c using tertiary operator. is it possible to do that?
$value = ($variable == 'b' or 'c')? true: false;
Is this possible?
I want to check if a variable is equal to b or c using tertiary operator. is it possible to do that?
$value = ($variable == 'b' or 'c')? true: false;
Is this possible?
Yes, separate your conditions using ||
operator, like so:
$value = ($variable == 'a' || $variable == 'b') ? true : false;
However, for this particular case, a ternary operator isn't necessary! You can directly use the return value:
$value = ($variable == 'a' || $variable == 'b');