2017 © Pedro Peláez
 

library unitformat

一个数据单位格式化的PHP组件

image

furthestworld/unitformat

一个数据单位格式化的PHP组件

  • Thursday, June 8, 2017
  • by xuanskyer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 73 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

unitFormat

一个数据单位格式化的PHP组件, (*1)

功能

提供数据的自动进位、格式化,并匹配单位, (*2)

安装

  • 在项目的composer.json文件中的require项中添加:
"furthestworld/unitformat": "~1.0"

并更新composer依赖:composer update, (*3)

  • 在需要使用的地方添加:
require_once __ROOT__ . '/vendor/autoload.php';
use FurthestWorld\UnitFormat\Src\UnitFormat;

用法

$origin_data    = [
    '2345124332',
    '3433443432',
    '12243433332',
    '7852323436'
];
$formatted_data = UnitFormat::formatDataUnit($origin_data, 10000, ['次', '万次', '亿次'], [1]);
var_dump($formatted_data);

输出结果:, (*4)

array(2) {
  ["unit"]=>
  string(6) "亿次"
  ["data"]=>
  array(4) {
    [0]=>
    string(4) "23.5"
    [1]=>
    string(4) "34.3"
    [2]=>
    string(5) "122.4"
    [3]=>
    string(4) "78.5"
  }
}

参数说明

formatDataUnit 方法

  • $origin_data :原始数据。可以是单个值,或者是一个数值数组列表, (*5)

  • $mod :单位进位的模, (*6)

  • $units :单位列表, (*7)

  • $number_format :使用PHP的number_format函数自定义参数数组,对应number_format的后三个参数列表, (*8)

updateDataUnit 方法

  • $origin_data : 原始数据的引用。 直接对原始数据格式化修改, (*9)

  • $key :需要格式化的数据数组 key, (*10)

  • $mod :单位进位的模, (*11)

  • $units :单位列表, (*12)

  • $number_format :使用PHP的number_format函数自定义参数数组,对应number_format的后三个参数列表, (*13)

updateMultiDataUnit : 直接对原始数据多组数据格式化修改

  • $origin_data : 原始数据的引用。, (*14)

  • $keys : 多个字段格式化设置数组, (*15)

格式如下:, (*16)

[
    'key1'  => ['mod' => 10000, 'units' => ['次', '万次', '亿次'], 'number_format' => [2, '.', ',']],
    'key2' => ['units' => ['个', '万个', '亿个']]
]

其他完善中。。。

The Versions

08/06 2017

v1.0.4

1.0.4.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.5.19

 

by Avatar xuanskyer

php unitformat

30/12 2016

dev-master

9999999-dev

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat

30/12 2016

v1.0.3

1.0.3.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat

29/12 2016

v0.0.2

0.0.2.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat

29/12 2016

v1.0.2

1.0.2.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat

29/12 2016

v1.0.1

1.0.1.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat

29/12 2016

v1.0.0

1.0.0.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat

29/12 2016

v0.0.1

0.0.1.0

一个数据单位格式化的PHP组件

  Sources   Download

MIT

The Requires

  • php >=5.6.19

 

by Avatar xuanskyer

php unitformat