How can I compare more than one string by using ==
and or
in PHP:
if ($variable == "string-1" or "string-2") {
// do something;
}
Is there any better or more formal method for comparing $variable
with a bunch of strings?
How can I compare more than one string by using ==
and or
in PHP:
if ($variable == "string-1" or "string-2") {
// do something;
}
Is there any better or more formal method for comparing $variable
with a bunch of strings?
Try this:
$values = [
'string-1',
'string-2',
];
if (in_array($variables, $values, true)) {
$variables = 'desired string';
}
For reference, see: