1. Go to this page and download the library: Download llcu/us-states 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/ */
llcu / us-states example snippets
use LLCU\UsStates\States;
// Get all 50 US states (abbreviation => name)
$states = States::all();
// ['AL' => 'Alabama', 'AK' => 'Alaska', ...]
// Get state name by abbreviation
$name = States::getName('CA');
// 'California'
// Get abbreviation by state name
$abbr = States::getAbbreviation('California');
// 'CA'
// Check if valid state
States::isValidState('CA'); // true
States::isValidState('DC'); // false (DC is a territory)
// Check if valid state
States::isValid('CA'); // true
States::isValid('DC'); // true
States::isValid('XX'); // false
// Get all abbreviations
$abbreviations = States::abbreviations();
// ['AL', 'AK', 'AZ', ...]
// Get all names
$names = States::names();
// ['Alabama', 'Alaska', 'Arizona', ...]
// Get count
$count = States::count();
// 50
// Search states by partial name
$results = States::search('new');
// ['NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York']
// Basic options
$options = States::asSelectOptions();
// With placeholder
$options = States::asSelectOptions(false, 'Select a state...');
// ['' => 'Select a state...', 'AL' => 'Alabama', ...]