PHP Classes

PHP Countries List Array: Get names and codes of all world countries

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 499 All time: 5,822 This week: 38Up
Version License PHP version Categories
php-countries-array 1.0.8GNU General Publi...5.3.0PHP 5, Statistics, Geography
Description 

Author

This class can get the names and codes of all world countries.

It contains an array with the list of all countries with their properties like names, continent, ISO 3166 2 or 3 letter country codes, ISD codes for making phone calls.

The class can get the whole array of countries or a given country by one of the stored properties.

Picture of sameer shelavale
  Performance   Level  
Name: sameer shelavale is available for providing paid consulting. Contact sameer shelavale .
Classes: 5 packages by
Country: India India
Age: 43
All time rank: 136675 in India India
Week rank: 200 Up20 in India India Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
/**
 * Created by PhpStorm.
 * User: sam
 * Date: 12/15/14
 * Time: 8:50 PM
 */
use SameerShelavale\PhpCountriesArray\CountriesArray;
include(
"../src/CountriesArray.php" );



$countries = CountriesArray::get();
var_dump( $countries );


$countries = CountriesArray::get2d( 'alpha3' );
var_dump( $countries );


$countries = CountriesArray::get2d( 'alpha3', array( 'name', 'isd', 'continent' ) );
var_dump( $countries );


$countries = CountriesArray::get2d( null, array( 'name', 'num', 'isd', 'continent' ) );
var_dump( $countries );


Details

php-countries-array

PHP class to get array of countries with ISO_3166-1, ISO_3166-2 and ISD codes it can provide following information related to the country

  1. name - Name of the country
  2. alpha2 - alpha2 code, 2 characters (ISO-3166-1 alpha2)
  3. alpha3 - alpha3 code, 3 characters (ISO-3166-1 alpha3)
  4. num - numeric code (ISO-3166-1 numeric)
  5. isd - ISD code for country
  6. continent - Name of the continent in which the country is present

Installation

PHP Include

Include CountryArray.php in your php code and you its ready to use.

Composer:

Add the package to your composer.json and run composer update.

{
    "require": {
        "sameer-shelavale/php-countries-array": "*"
    }
}

Usage

Get simple key-value array by default it returns alpha2 => name pairs

$countries = CountriesArray::get();

Include non iso countries:

$countries = CountriesArray::iso(false)->get();

Get key values pairs

$countries = CountriesArray::get( 'alpha2', 'name' ); // returns alpha2->name array
$countries = CountriesArray::get( 'num', 'alpha3' ); // return numeric-codes->alpha3 array
$countries = CountriesArray::get( 'num', 'name' ); // return numeric-codes->name array

Get only values without keys

$countries = CountriesArray::get( null, 'name' ); // return array of country names
$countries = CountriesArray::get( null, 'alpha2' ); // return array of alpha2 codes

Get 2d array

$countries = CountriesArray::get2d( null, 'name' ); // return array of country names
$countries = CountriesArray::get2d( null, 'alpha2' ); // return array of alpha2 codes

Get countries filtered by continent

$countries = CountriesArray::getFromContinent( 'alpha2', 'name', 'Africa' ); // returns alpha2->name array of countries from Africa
$countries = CountriesArray::getFromContinent( 'num', 'alpha3', 'Asia' ); // return numeric-codes->alpha3 array of countries from Asia
$countries = CountriesArray::getFromContinent( 'num', 'name', 'Europe' ); // return numeric-codes->name array of countries from Europe

IMP Note

Do not use ISD code(isd) and continent as key fields, as there are multiple records for them


  Files folder image Files (4)  
File Role Description
Files folder imagesample (1 file)
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (4)  /  sample  
File Role Description
  Accessible without login Plain text file sample1.php Example Example script

  Files folder image Files (4)  /  src  
File Role Description
  Plain text file CountriesArray.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:499
This week:0
All time:5,822
This week:38Up