PHP code example of rebilly / country

1. Go to this page and download the library: Download rebilly/country 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/ */

    

rebilly / country example snippets


use Country\AdministrativeAreaRepository;
use Country\CountryRepository;

$countryRepository = new CountryRepository();
$administrativeAreaRepository = new AdministrativeAreaRepository($countryRepository);

// get a list of all countries
$countries = $countryRepository->findAll();

if ($countryRepository->hasWithIsoAlpha2('US')) {
    $usa = $countryRepository->findByIsoAlpha2('US');
    echo $usa->getCommonName(); // United States
    echo $usa->getOfficialName(); // United States of America

    // get a list of all US states
    $administrativeAreaRepository->findByCountry($usa);

    if ($administrativeAreaRepository->hasWithNameAndCountry('New York', $usa)) {
        $newYork = $administrativeAreaRepository->findByNameAndCountry('New York', $usa);
        echo $newYork->getCode(); // NY
    }
}