Let's say I have a switch statement like this:
switch($myVar)
{
case 'A':
$special = 1;
$total = $special + 5;
break;
case 'B':
$special = 2;
$total = $special + 5;
break;
case 'C':
$special = 3;
$total = $special + 5;
break;
}
As you can see above, the only thing that differs from the cases of my switch statement is the variable $special
. Its value should be 1 if case is A and 2 if case is B and so on. Apart from that the rest of the code after that stays the same. Is there a way that I can organize this switch statement to remove the duplicate code:
$total = $special + 5
Thank you