Looking for an easier way to accomplish:
$switch_success = false;
switch ($var){
case "a":
// do some stuff
$switch_success = true;
break;
case "b":
// do some stuff
$switch_success = true;
break;
case "c":
// do some stuff
$switch_success = true;
break;
}
if ($switch_success){
// switch was successful - run once only if switch finds a matching case
}
Maybe another case keyword like default only for any or all:
case "c":
// do some stuff
break;
all:
// switch was successful - run once only if switch finds a matching case
Or maybe …
$switch_success = switch ($var){
case "a":
// do some stuff
break;
case "b":
// do some stuff
break;
case "c":
// do some stuff
break;
}
if ($switch_success) //...
Just tried that to no avail, but just trying to illustrate my intent.
Try
$switch_success=1;at the top, anddefault: $switch_success=0;at the end of the switch.