SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple IF Statements or Array?

    Hello forum!

    I have a custom field in Wordpress which is populated with a country code: GB, IT, ES.. (around 40 of them)..

    Looking for efficient PHP code to display to user the respective country's name for each country code..

    Any help is much appreciated..

    thanks,
    Andy

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,077
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    I'd say the easiest way is an array

    PHP Code:
    <?php
    $countries 
    = array(
        
    'BE' => 'Belgium',
        
    'NL' => 'The Netherlands',
        
    'GB' => 'Great Brittain',
        
    'US' => 'USA',
        
    // etc
    );

    $county array_key_exists($country_code$countries) ? $countries[$country_code] : 'Unknown country';
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks - this is quite neat!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •