PHP - hash_copy() 函式



定義和用法

hash_copy() 函式用於複製由 hash_init() 生成的雜湊上下文。

語法

hash_copy ( HashContext $context ) : HashContext

引數

序號 引數及描述
1

HashContext context

使用 hash_init() 獲取的雜湊上下文。

返回值

hash_copy() 函式返回雜湊上下文的副本。該雜湊上下文可與其他雜湊函式一起使用,例如 hash_update()、hash_update_stream()、hash_update_file() 和 hash_final()。

PHP 版本

此函式可在 PHP 5.3.0 以上版本中使用。

示例 1

hash_copy() 和 hash_init() 的工作原理 -

<?php
   $hash_context = hash_init("md5");
   hash_update($hash_context, "Welcome To Tutorialspoint");
   $hash_copy= hash_copy($hash_context);
   echo hash_final($hash_context);
   echo "<br/>";
   hash_update($hash_copy,  "Welcome To Tutorialspoint");
   echo hash_final($hash_copy);
?>

輸出

這將產生以下結果 -

6211420491a571f89f970683221d4480<br/>d0b25da996bf035057aba79082c53b30

示例 2

hash_copy() 與 sha256 的工作原理 -

<?php
   $hash_context = hash_init("sha256");
   hash_update($hash_context, "Welcome To Tutorialspoint");
   $hash_copy = hash_copy($hash_context);
   hash_update($hash_copy,  "Welcome To Tutorialspoint");
   echo hash_final($hash_copy);
?>

輸出

這將產生以下結果 -

5fc2dcb68e98dee511cd5bc72667a1acaaf769c737f094672ab9072e5543f587
php_function_reference.htm
廣告