check whether a country is in EU in PHP

This could be useful to someone else:

This simple function takes a country code as parameter and returns TRUE if it’s in European Union (EU) or FALSE otherwise.

function isEU($countrycode) {
    $eu_countrycodes = array(
        'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL',
        'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV',
        'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'
    );
    return (in_array($countrycode, $eu_countrycodes));
}

Could be useful in online shops for example.

7 Responses to “check whether a country is in EU in PHP”

  1. Yun

    Thanks for sharing your code, but there is a mistake. ‘CH’ is not in EU, and you should remove it and add ‘HR’ to the list.

    Reply
  2. Lennard

    Thanks for this function! GR seems to be missing in that list though and HR is not aligned with the sorting of the others.

    Reply
      • Lennard

        Thanks for the fix! Another missing one I spotted: LU (Luxembourg)

        Reply
        • Hannes

          no… Luxembourg is there, maybe you have to scroll a little bit to the right side
          but we can remove Great Britain today…

          Reply
  3. greg

    smalll improvement
    function isEU($countrycode) {
    $eu_countrycodes = array(
    ‘AT’, ‘BE’, ‘BG’, ‘CY’, ‘CZ’, ‘DE’, ‘DK’, ‘EE’, ‘EL’,
    ‘ES’, ‘FI’, ‘FR’, ‘GR’, ‘HR’, ‘HU’, ‘IE’, ‘IT’, ‘LT’, ‘LU’, ‘LV’,
    ‘MT’, ‘NL’, ‘PL’, ‘PT’, ‘RO’, ‘SE’, ‘SI’, ‘SK’
    );
    return (in_array(strtoupper($countrycode), $eu_countrycodes));
    }

    Reply

Leave a Reply