PHP code example of agallou / regions

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

    

agallou / regions example snippets


$regions = new \agallou\Regions\Collection();
var_dump($regions->get('11')->getLabel());
//string(10) "Ile-de-France"

$regions = new \agallou\Regions\Collection();
var_dump($regions->getLabel(2, true));
//string(10) "Martinique"

$regions = new \agallou\Regions\Collection();
var_dump($regions->get('82')->getCodesDepartements());
//array(8) {
//[0]=>
//  string(2) "01"
//[1]=>
//  string(2) "07"
//[2]=>
//  string(2) "26"
//[3]=>
//  string(2) "38"
//[4]=>
//  string(2) "42"
//[5]=>
//  string(2) "69"
//[6]=>
//  string(2) "73"
//[7]=>
//  string(2) "74"
//}

$departements = new \agallou\Departements\Collection();
foreach ($departements as $code => $label) {
  var_dump($code, $label);
}
//int(42)
//string(6) "Alsace"
//int(72)
//string(9) "Aquitaine"
//int(83)
//string(8) "Auvergne"
//...
//int(82)
//string(12) "Rhône-Alpes"

$regions = new \agallou\Regions\Collection2016();
var_dump($regions->get('84')->getLabel());
//string(10) "Auvergne-Rhône-Alpes"