cromwell / iso3166
A simple package for working with ISO-3166 country codes
Installs: 61 508
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: *
README
Package for interacting with ISO3166 country codes
Example Usage
$iso = new \Cromwell\ISO3166\Countries(); $iso[$iso::UNITED_KINGDOM]->name;
The above isn't hugely useful, it gets more interesting when the code has been stored and retrieved from persistence:
$iso = new \Cromwell\ISO3166\Countries(); $iso[$customer->country]->name;
You can also use jsonSerialize()
either for JSON encoding or as a convenient way to get a multidimensional array for use to construct a <select>
box of code => name.
Subsets
You can construct any subset of countries by passing an array of codes. The package contains an EU subset at the moment, you can use the EU class as an example of how to do it or if you just wanted EU countries, there you go.
Passing an array of codes is useful if they've been selected on the fly by an end user. It could be a list of countries that they ship to, for example. In this instance it's likely to change between customers or be initialised from the database. If it's a static list, such as a continent or EU membership, use the EU example and extend the base Countries class to implement your subset.