定制 llcu/us-states 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-16