Interesting Switch case Optimization

Details at:

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

Popular posts from this blog

Opencart error: Notice: Trying to access array offset on value of type null in ..../vendor/scss.inc.php on line 1753

Creating Class Templates

Fixed: Opencart installation error linux: warning: fopen(system/storage) failed to open stream: Permission denied