PHP code example of petercoles / multilingual-country-list

1. Go to this page and download the library: Download petercoles/multilingual-country-list library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

petercoles / multilingual-country-list example snippets


    'providers' => [
        // ...
        PeterColes\Countries\CountriesServiceProvider::class,
        // ...
    ],

'Countries' => PeterColes\Countries\CountriesFacade::class,

Countries::lookup();

// returns

{
  "AF": "Afghanistan",
  ...
  "ZW": "Zimbabwe"
}


Countries::lookup('es', true);

// returns

{  
  "Afganistán": "AF",
  ...
  "Zimbabue": "ZW"
}


Countries::lookup('zh_CN');

// returns

{
  "AL": "阿尔巴尼亚",
  ...
  "HK": "中国香港特别行政区"
}


Countries::keyValue();

// returns

[
  {"key": "AF", "value": "Afghanistan"},
  ...
  {"key": "ZW", "value": "Zimbabwe"}
]

Countries::keyValue('zh', 'label', 'text');

// returns

[
  {"label": "AL", "text": "阿尔巴尼亚"},
  ...
  {"label": "HK", "text": "中国香港特别行政区"}
]

Countries::countryName('BE', 'fr')

// returns

'Belgique'

Countries::lookup()->reject(function($country, $key) {
    return $key == 'EZ';
});

Countries::lookup()->reject(function($country, $key) {
    return in_array($key, [ 'EZ', 'IC', 'GP' ]);
});

Countries::lookup()->mapWithKeys(function($country, $key) {
    return $key == 'GB' ? [ 'UK' => $country ] : [ $key => $country ];
});

Countries::lookup()->put('CT', 'Catalonia')->sort();