rkr/php-array-utils
Composer 安装命令:
composer require rkr/php-array-utils
包简介
A array-function library
README 文档
README
A array-function library
$input = ['a' => 0, 'b' => 1, 'c' => 2, 'd' => 3]; arr\join($input); # 0123 arr\join($input, ', '); # 0, 1, 2, 3 arr\intersect($input, [1, 3]); # [b => 1, d => 3] arr\intersect\keys($input, ['a', 'b']); # [a => 0, b => 1] arr\diff($input, [1, 2]); # [a => 0, d => 3] arr\diff\keys($input, ['a', 'c']); # [b => 1, d => 3] arr\filter($input); # [b => 1, c => 2, d => 3] arr\filter($input, function ($val) { return $val !== 1; }); # [a => 0, c => 2, d => 3] arr\filter\keys($input); # [a => 0, b => 1, c => 2, d => 3] arr\filter\keys($input, function ($key) { return $key !== 'b'; }); # [a => 0, c => 2, d => 3] arr\filter\keysAndValues($input, function ($key, $value) { return $value === 0 || $key === 'b'; }); # [a => 0, b => 1] arr\map($input, 'exp'); # [a => 1, b => 2.718281828459, c => 7.3890560989307, d => 20.085536923188] arr\map($input, function ($val) { return $val + 1; }); # [a => 1, b => 2, c => 3, d => 4] arr\map\keys($input, 'strtoupper'); # [A => 0, B => 1, C => 2, D => 3] arr\map\keys($input, function ($key) { return dechex(ord($key)); }); # [61 => 0, 62 => 1, 63 => 2, 64 => 3] arr\map\keysAndValues($input, function (&$key, $value) { list($value, $key) = array($key, $value); return $value; }); # [0 => a, 1 => b, 2 => c, 3 => d] arr\map\func([[255, 128, 0], [128, 255, 0]], 'vsprintf', array('#%02X%02X%02X'), 1); # [0 => #FF8000, 1 => #80FF00]
FAQ
Hey, all the cool kids use OOP. Isn't this library pointing in the wrong direction?
It depends either on the situation or the extent in which an array is used. In PHP, arrays are often meat in different situations. At least, $_-variables are arrays. You can immediately wrap an Array into an ArrayObject, but then you can't use many of the features built into PHP directly. So I think I have to explain the advantages and disadvantages of each approach:
Advantage of array-functions:
- You don't have to make an object out of every array you wan't to apply certain functionality on.
- You can still use php's built in functions like array_merge() on arrays without the need for conversion.
- You can add as many functions by yourself as you wish. You could so the same with an ArrayObject-descendant, but then you end up with a god-object with tens or hundreds of methods (Closure-bindung?).
- You can always use the array-typehint and still utilize the extensions of this library directly.
Disadvantages of array-functions:
- Everytime you pass an array as a parameter to a function/method, the whole array gets copied.
- You can utilize an inner state that can help to track changes or whatever.
rkr/php-array-utils 适用场景与选型建议
rkr/php-array-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 113 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rkr/php-array-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rkr/php-array-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 113
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-24