承接 gupalo/arrayutils 相关项目开发

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

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

gupalo/arrayutils

Composer 安装命令:

composer require gupalo/arrayutils

包简介

Array utils

README 文档

README

Install

composer require gupalo/arrayutils

Features

All code is covered by tests. Look at tests to understand better how it's working.

All methods are static.

Items can be iterable (array, \Generator, ...) of one of:

  • array
  • object with public properties or getters (anything Symfony PropertyAccessor can get)

ArrayAggregator

  • max(items, field): max field value among items
  • sum(items, field): sum of field values of items
  • ratio(items, field, field2: "sum by field"/"sum by field2"
  • maxRatio(items, field, field2): max among "field value"/"field value2"

ArrayComparer

Comparing is smart - if compared values are float, they are rounded with precision = 8.

  • compareOne(a1, a2, keys): check that each (string)a1[key] === (string)a2[key] for each of keys. returns "patch" how to go from a1 to a2. null value means that we need to unset this key.
  • compare(a1, a2, keys) a1 and a2 are expected to be array of arrays. returns patch how what's changed in a2 compared to a1 - array with keys:
    • created: which items should be created and their values
    • updated: which items should be updated and updated fields
    • removed: which items (ids) should be deleted
  • compareFlat(a1, a2) similar to compare but a1 and a2 are considered scalars and are compared fully, not by fields

ArrayFactory

  • createKeys(keys, value): create array with these keys and value
  • createDictionary(a, keyColumn, valueColumn): similar to array_column(a, valueColumn, keyColumn) but doesn't require values present in all items (?? null)

ArrayKeysHelper

  • index($a, array|string $keys = 'id'): create indexed array where index may contain several fields
  • indexAndGroup($a, array|string $keys = 'id'): create indexed array but allow several items with same index
  • fill($a, $keys, $defaultValue = null): ensure that all keys exist in array and all others are missing
  • filter($a, $keys, $createMissingKeys = true): get these keys from array
  • unset($a, $keys): unset these keys from each array item

ArrayRandom

  • pick(array $items): select random value from array
  • pickMultiple(array $items, int $count = 1, bool $preserveKeys = false, mixed $default = []): select multiple ($count) random values from array

ArrayTable

  • arrayToKeyValues(array $data): covert table (like TSV; first item is header with keys) to array with named keys

ArrayUniquer

  • values(array $a): uniq -> values
  • notNullValues(array $a): filter not null -> uniq -> values
  • columnValues(array $a, string $column): column -> uniq -> values
  • mergeValues(...$a): merge -> uniq -> values
  • mergeNotNullValues(...$a): merge -> filter not null -> uniq -> values

FloatArrayFactory

  • createPreserveKeys(array $a): ensure that all values are float
  • create(array $a): ensure that all values are float -> values

IntArrayFactory

  • createPreserveKeys(array $a): ensure that all values are int
  • create(array $a): ensure that all values are int -> values

Balancer

Problem to solve: you have some items and need to split them to some buckets. You may configure different strategies how to distribute your items between the buckets. Buckets should implement BucketInterface, balancer should implement BalancerInterface

SemiRandomBalancer

It's not fully random, you set seed so multiple runs with the same seed and same items will lead to the same result.

FairBalancer

Try to make same weighted count of items in same bucket.

Example: A/B test where you want to send 90% of users to "A" page and 10% to "B" page. You could use simple random but with low amount of users it's quite probable that you have 20 users and all will see page "A" or 5 users that go to "B". Then you'll have hard time explaining probability theory. With this balancer you may be sure that 1 of the first 10 users will go to "B" and most probably 2 of 20 users will land there.

gupalo/arrayutils 适用场景与选型建议

gupalo/arrayutils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.33k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 gupalo/arrayutils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gupalo/arrayutils 我们能提供哪些服务?
定制开发 / 二次开发

基于 gupalo/arrayutils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-20