lindowx/php-array-hash 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lindowx/php-array-hash

最新稳定版本:v0.2.1

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固