Interesting Switch case Optimization
Details at:
https://derickrethans.nl/php7.2-switch.html
https://derickrethans.nl/php7.2-switch.html
<?php
$cc = "no";
$_table = [ "de" => 1, "en" => 2, "nl" => 3, "no" => 4 ];
if (gettype($cc) == 'string') {
if (array_key_exists($cc, $_table)) {
goto "jmp_{$_table[$cc]}";
} else {
goto jmp_default;
}
} else {
/* do original if/else if/else sequence */
}
jmp_1: echo "DEUTSCH"; goto end;
jmp_2: echo "English"; goto end;
jmp_3: echo "Nederlands"; goto end;
jmp_4: echo "Norsk"; goto end;
jmp_default: echo "unknown";
end:
?>

Comments
Post a Comment