The switch needs literals in case blocks. Use if instead.
You can use other types of loops in iterate through the value, and then use if to compare. Comparison / condition checking is not possible in switch cases.
One way to accomplish what you want to do is this (note that IF is used):
$value = 'AA'; switch($value) { case ('AA'): echo "value equals 1<br />"; case ('BB'): if ($value == 'BB'){ echo "value equals 2<br />"; } case (('AA') || ('CC')): echo "value equals 3<br />"; break; }
Outputs:
value equals 1 value equals 3
NOTE. - The above solution does not fit, although it outputs what you need, it is not the right solution, and, if possible, I would recommend avoiding it. Your needs can be easily eliminated using alternatives without switching / case.
source share