Reputation: 10240
In the following example, sometimes $var
can be "Value", "value" or even "VALUE".
switch ( $var ) {
case "value":
// Value and VALUE don't seem to match here.
break;
}
The comparison seems to be case sensitive (only the all-lowercase "value" matches). Is there a way to perform a case-insensitive comparison?
Ref: http://php.net/manual/en/control-structures.switch.php
Upvotes: 3
Views: 1927
Reputation: 11084
Convert your string to lowercase, then compare it to all lowercase strings
switch ( strtolower($var) ) {
case "value":
// Value and VALUE don't seem to match here.
break;
}
Upvotes: 3
Reputation: 514
$var = strtolower($var)
And then in the switch cases write all lowercase
Upvotes: 2