承接 senseexception/intl-sort 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

senseexception/intl-sort

最新稳定版本:3.0.0

Composer 安装命令:

composer require senseexception/intl-sort

包简介

A wrapper library for PHP Intl to sort values based on rules of locales

README 文档

README

A wrapper library for PHP Intl to sort values/objects based on rules of locales.

This library wraps the Collator class of the PHP Intl extension and offers a more fluid API without constant juggling for you to sort your values or objects by country/locale specific standards.

Latest Stable Version PHP from Packagist Tests Static Analysis License

Why using this library?

PHP functions like sort() work most of the time when it comes to sort values, but they don't return useful results when a country or language specific order of values is needed like e.g. words with umlauts or other accents.

This library wraps the Collator class of the PHP Intl extension and offers a builder pattern API to create a Sorter to sort values or value objects by the rules of a locale. You also can implement your own sorting logic.

Installation

You can install this with Composer.

composer require senseexception/intl-sort

Documentation

Read more about what this library is capable of in the documentation.

Examples

While PHP's own sort functions don't order the elements in a way that is expected in different countries, intl-sort will sort them with the help of the Intl-extension appropriate for the countries in your international project.

Ascending order

$sortBuilder = new \Budgegeria\IntlSort\Builder('de_DE');
$sorter = $sortBuilder->getSorter();

$sortedArray = $sorter->sort(['a', 'g', 'A', 'ß', 'ä', 'j', 'z']);

var_dump($sortedArray); // [0 => 'a', 2 => 'A', 4 => 'ä', 1 => 'g', 5 => 'j', 3 => 'ß', 6 => 'z'];

Descending order

$sortBuilder = new \Budgegeria\IntlSort\Builder('de_DE');
$sorter = $sortBuilder->orderByDesc()->getSorter();

$sortedArray = $sorter->sort(['a', 'g', 'A', 'ß', 'ä', 'j', 'z']);

var_dump($sortedArray); // [0 => 'z', 1 => 'ß', 2 => 'j', 3 => 'g', 4 => 'ä', 5 => 'A', 6 => 'a',];

Order by keys

$sortBuilder = new \Budgegeria\IntlSort\Builder('de_DE');
$sorter = $sortBuilder->orderByKeys()->getSorter();

$sortedArray = $sorter->sort(['g' => 1, 'A' => 2, 'ß' => 3, 'ä' => 4, 'z' => 5]);

var_dump($sortedArray); // ['A' => 2, 'ä' => 4, 'g' => 1, 'ß' => 3, 'z' => 5];
$sortBuilder = new \Budgegeria\IntlSort\Builder('de_DE');
$sorter = $sortBuilder->orderByKeys()->orderByDesc()->getSorter();

$sortedArray = $sorter->sort(['g' => 1, 'A' => 2, 'ß' => 3, 'ä' => 4, 'z' => 5]);

var_dump($sortedArray); // ['z' => 5, 'ß' => 3, 'g' => 1, 'ä' => 4, 'A' => 2,];

There are also more configuration possibilities in the builder like setting strength, lower case first / upper case first or special french collation.

Does it affect GDPR somehow?

intl-sort itself uses the locale only for the purposes to sort values with the help of the PHP Intl extension.

统计信息

  • 总下载量: 3.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固