Search code examples
phpsteam-web-apigarrys-mod

Shorten useless coding?


Creating my loading screen on garrys mod, and seeing this "useless" coding, and was betting that there is a way to shorten it massively, however I am quite a php nooby and was wondering if there was a perhaps a way to use arrays or something to make it easier/shorter? Code Here


Solution

  • $array = array(
       "gm_flatgrass" => "Flatgrass",
       "cs_assault" => "CS Assault",
       "de_train" => "",
       ...
    );
    
    $getmap = $_GET['mapname'];
    
    if(array_key_exists($getmap,$array)) {
        $map =  $array[$getmap];
    }