lindowx/php-array-hash
Composer 安装命令:
composer require lindowx/php-array-hash
包简介
Hashing an multi-dimension PHP array into a unique value
README 文档
README
A PHP array hashing library that can hashing multi-dimension array into a unique string value.
Requirements
PHP >= 7.3
Installation
composer require lindowx/php-array-hash
Usage
/** * Array hashing * * @param array $arr The array data you want to hash * @param callable $func Hash algo function * @param int $options Hashing options */ Lindowx\PHPArrayHash\ArrayHash::hash(array $arr, callable $func, int $options = 0): string;
Hashing options
- ArrayHash::OPT_NIA_IGNORE_ORDER Ignore the value order when the source array contains num-index lists
Examples
use Lindowx\PHPArrayHash\ArrayHash; $arr1 = [ 'a' => 3, 'b' => 'hello, world', 'c' => [ [1, 2, 3], [4, 5, 6], ], ]; $arr2 = [ 'a' => 3, 'b' => 'hello, world', 'c' => [ [4, 6, 5], [3, 1, 2], ], ]; // SHA-1 hashing // 4dea90f136ff0bdeb8da5a7da0f03b1858d62b16 $arrSha1Hash = ArrayHash::hash($arr1, 'sha1'); // MD5 hashing // 32a02c4310e4c71c27fd5a42b25d0e73 $arrMd5Hash = ArrayHash::hash($arr1, 'md5'); // Custom hashing //09ce8e0554ed842d50162e28710331415735e7f618b1caa396f28ab0f3cd99d9 $arrCustomHash = ArrayHash::hash($arr1, function ($stub) { $key = 'this is a key'; return hash_hmac('sha256', $stub, $key); }); // 80895b6e8ab6d0d4d1201f84b3ba8b5f70bb50ea $arr1Sha1NumIdxListIgnoreOrder = ArrayHash::hash($arr1, 'sha1', ArrayHash::OPT_NIA_IGNORE_ORDER); // 80895b6e8ab6d0d4d1201f84b3ba8b5f70bb50ea $arr2Sha1NumIdxListIgnoreOrder = ArrayHash::hash($arr2, 'sha1', ArrayHash::OPT_NIA_IGNORE_ORDER);
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
lindowx/php-array-hash 适用场景与选型建议
lindowx/php-array-hash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.46k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lindowx/php-array-hash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lindowx/php-array-hash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-03