PHP code example of ggggino / italy-municipality

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

    

ggggino / italy-municipality example snippets


/** @var IstatRetrivier $retrivier */
$retrivier = $this->get(IstatRetrivier::class);

/** @var CsvLine[] $municipalities */
$municipalities = $retrivier->getMunicipalities();

/** @var CsvLine[] $provinces */
$provinces = $retrivier->getProvinces();

/** @var CsvLine[] $regions */
$regions = $retrivier->getRegions();

/** @var CsvLine[] $lines */
$retrivier->getBy(function($csvLines) {
    /** @var CsvLine[] $regions */
    $regions = array();

    /** @var CsvLine $line */
    foreach($csvLines as $line) {
        if( !array_key_exists($line->codiceProvincia, $regions) ){
            $regions[$line->codiceProvincia] = $line;
        }
    }

    return $regions;
}, 'string_used_as_key_if_you_want_to_push_to_cache_otherwise_not_pushed');

$formMapper
    ->add('comune',MunicipalityType::class)
    ->add('provincia', ProvinceType::class)
    ->add('regione', RegionType::class)