PHP Function Reference

PHP hash_copy() Function



The PHP hash_copy() function is used to copy hashing context generated by hash_init().

Syntax

hash_copy(context)

Parameters

context Required. Specify the hashing context returned by hash_init() function.

Return Value

Returns a copy of Hashing Context.

Example: hash_copy() example

The example below shows the usage of hash_copy() function.

<?php
//initializing an incremental hashing context
$context = hash_init("md5");
//updating context
hash_update($context, "Hello World!");

//coping context using hash_copy function
$copy_context = hash_copy($context);

//finalizing an incremental hash
//and returning resulting digest
echo hash_final($context)."\n";

//updating copied context and finalizing the 
//incremental hash and returning resulting digest
hash_update($copy_context, "Hello World!");
echo hash_final($copy_context), "\n";
?>

The output of the above code will be:

ed076287532e86365e841e92bfc50d8c
ee41c968530f7715ab70805b341c3956

❮ PHP Hash Reference