• PHP Video Tutorials

PHP - Hash copy() Function



Definition and Usage

The hash_copy() function is used to copy the hashing context generated from hash_init().

Syntax

hash_copy ( HashContext $context ) : HashContext

Parameters

Sr.No Parameter & Description
1

HashContext context

The hash context that you get using hash_init().

Return Values

The hash_copy() function returns a copy of hash context. The hash context can be used with other hash function like hash_update(), hash_update_stream(), hash_update_file(), and hash_final().

PHP Version

This function will work from PHP Version greater than 5.3.0.

Example 1

Working of hash_copy() and 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);
?>

Output

This will produce the following result −

6211420491a571f89f970683221d4480<br/>d0b25da996bf035057aba79082c53b30

Example 2

Working of hash_copy() with 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);
?>

Output

This will produce the following result −

5fc2dcb68e98dee511cd5bc72667a1acaaf769c737f094672ab9072e5543f587
php_function_reference.htm
Advertisements