llcu/us-states
最新稳定版本:1.0.0
Composer 安装命令:
composer require llcu/us-states
包简介
A PHP package providing US states data with static method access
README 文档
README
A PHP package providing US states data with static method access.
Requirements
- PHP 8.3 or higher
Installation
composer require llcu/us-states
Usage
All methods are static, so no instantiation is required.
Get All States
use LLCU\UsStates\States; // Get all 50 US states (abbreviation => name) $states = States::all(); // ['AL' => 'Alabama', 'AK' => 'Alaska', ...]
Lookup Methods
// Get state name by abbreviation $name = States::getName('CA'); // 'California' // Get abbreviation by state name $abbr = States::getAbbreviation('California'); // 'CA'
Validation
// 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
Lists
// 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
// Search states by partial name $results = States::search('new'); // ['NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York']
HTML Select Options
// Basic options $options = States::asSelectOptions(); // With placeholder $options = States::asSelectOptions(false, 'Select a state...'); // ['' => 'Select a state...', 'AL' => 'Alabama', ...]
Random State
$random = States::random(); // ['abbreviation' => 'CA', 'name' => 'California']
Testing
This project uses Pest for testing.
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-16