Kotchasan Framework Documentation
Province
Province
Kotchasan\Province is a utility class for managing province data, including retrieving lists of provinces, converting names to ISO codes, and supporting multiple languages (Thai/English). Currently, it supports data for Thailand (TH) and Laos (LA).
Basic Usage
Retrieving All Provinces
use Kotchasan\Province;
// Get all provinces for Thailand (Default)
// Returns an Array [ISO Code => Province Name]
$provinces = Province::all('TH');
print_r($provinces);
/*
Array (
[10] => Bangkok
[81] => Krabi
...
)
*/Getting Province Name by ID (ISO Code)
// Get province name for ID 10 (Bangkok)
echo Province::get('10'); // "Bangkok" (Based on current system language)
// Specify language
echo Province::get('10', 'en'); // "Bangkok"
echo Province::get('10', 'th'); // "กรุงเทพมหานคร"Methods
all(string $country = 'TH'): array
Returns an array of all provinces where keys are ISO codes and values are province names (in the current language).
- $country: Country code (TH, LA)
- Returns: Array of provinces
get(int|string $iso, string $lang = '', string $country = 'TH'): string
Get province name from ISO code.
- $iso: Province ISO Code
- $lang: Desired language (th, en). Defaults to system language if empty.
- Returns: Province name or empty string if not found.
getOptions(string $country = 'TH'): array
Returns a list of provinces formatted for Dropdown/Select Box usage.
- Returns: Array of
['value' => iso, 'text' => name]
$options = Province::getOptions();
/*
Array (
[0] => Array ('value' => 10, 'text' => Bangkok)
...
)
*/isoFromProvince(string $province, string $lang = '', string $country = 'TH'): string
Find ISO code from province name (Case-sensitive for English).
- $province: Province name
- Returns: ISO code (string) or empty string if not found.
echo Province::isoFromProvince('Bangkok', 'en'); // "10"countries(): array
Returns a list of supported country codes.
- Returns:
['TH', 'LA']
Supported Countries
- TH: Thailand (supports th, en)
- LA: Laos (supports th, la, en)
Practical Example
Creating a Select Tag
use Kotchasan\Province;
// Using with Form class
$form->add('select', [
'id' => 'province',
'label' => 'Province',
'options' => Province::all('TH'),
'value' => $user_province
]);