function countries_api_get_array in Country codes API 6
Same name and namespace in other branches
- 5 countries_api.module \countries_api_get_array()
Function to return an associative array of countries with key/values based on args Can be used to get results for FAPI form options.
Parameters
$key_format: The format of the key (a value from countries_api_formats)
$value_format: The format of teh value (a value from countries_api_formats)
Return value
array An associative array based on arguments
2 calls to countries_api_get_array()
- CountriesAPITestCase::test_countries_api_get_array in tests/
countries_api.test - Function to test countries_api_get_array() results
- countries_api_get_options_array in ./
countries_api.module - Function for returning an associative array useful for FAPI select elements
File
- ./
countries_api.module, line 241 - Countries API provides an API for official and up-to-date ISO 3166 country codes (alpha-2 and alpha-3) and names (official short names).
Code
function countries_api_get_array($key_format = COUNTRIES_API_FORMAT_ISO2, $value_format = COUNTRIES_API_FORMAT_PRINTABLE_NAME) {
if (!countries_api_validate_format($key_format) || !countries_api_validate_format($value_format)) {
return FALSE;
}
$rows = array();
foreach (countries_api_get_list() as $country) {
$rows[$country[$key_format]] = $country[$value_format];
}
return $rows;
}