PHP code example of wnx / php-swiss-cantons
1. Go to this page and download the library: Download wnx/php-swiss-cantons 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/ */
wnx / php-swiss-cantons example snippets
use Wnx\SwissCantons\CantonManager;
$cantonManager = new CantonManager();
/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByAbbreviation('zh');
$canton = $cantonManager->getByName('Zurigo');
$canton = $cantonManager->getByZipcode(8000);
// "Zürich"
$cantonName = $canton->setLanguage('de')->getName();
$cantonManager = new Wnx\SwissCantons\CantonManager();
/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByAbbreviation('GR');
$cantonManager = new Wnx\SwissCantons\CantonManager();
/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByName('Zürich');
$cantonManager = new Wnx\SwissCantons\CantonManager();
/** @var \Wnx\SwissCantons\Canton[] $cantons */
$cantons = $cantonManager->getByZipcode(3005);
$cantonManager = new Wnx\SwissCantons\CantonManager();
/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByZipcodeAndCity(1003);
$canton = $cantonManager->getByZipcodeAndCity(1290, 'Lausanne');
$canton->setLanguage('rm');
$canton->setLanguage('fr')->getName();
$canton->getName(); // Grisons
$canton->setLanguage('de')->getName(); // Graubünden
$canton->getAbbreviation(); // e.g. ZH
use Wnx\SwissCantons\Cantons;
$cantons = (new Cantons)->getAll();
use Wnx\SwissCantons\Cantons;
$cantons = (new Cantons)->getAllAsArray('en');
$cantonsAsArray = $cantons->getAllAsArray();
// var_dump($cantonsAsArray);
// [
// 'ZH' => 'Zurich',
// 'GE' => 'Geneva',
// // ...
// ]
shell
composer