drnycqxwz63508434 2013-03-05 03:42
浏览 46
已采纳

缺少array_hash()函数。 无法创建数组的哈希值

Intro:

I need a function that can take an array and return a hash of it.

This should similar to spl_object_hash(), except that it returns a hash for given array.

So, far I've tried

function array_hash(array $array) {

   return spl_object_hash((object) $array); 
}

The problems

1) This algorithm isn't efficient by itself. For example, what if I pass something like this:

  $array = array(
     'foo' => 'bar',
     'bool' => false,
     'junk' => array(
         'junk1' => array('foo' => array('__test__'))
      )
  )

It won't cast nested arrays to objects.

2) Another major problem is that, spl_object_hash() returns a different hash for the same object on each new HTTP request.

The question

Again: I need a persistent hash for an array. Unlike spl_object_hash(), the will be persistent on each HTTP request. How can I do this correctly?

  • 写回答

2条回答 默认 最新

  • doufen2769 2013-03-05 03:47
    关注

    How about serializing the array first?

    md5(serialize($array));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?