PHP | hash_copy() Function
Last Updated :
29 Oct, 2018
The hash_copy() function is an inbuilt function in PHP which is used to get the copy of hashing context.
Syntax:
hash_copy( $context )
Parameters: This function accepts single parameter $context which is used to specify the hashing context returned by hash_init() function.
Return Value: This function returns a copy of Hashing Context.
Below programs illustrate the hash_copy() function in PHP:
Program 1:
<?php
$context = hash_init( "sha1" );
$cp_context = hash_copy( $context );
echo hash_final( $context ), "\n" ;
hash_update( $cp_context , "GFG" );
echo hash_final( $cp_context ), "\n" ;
?>
|
Output:
da39a3ee5e6b4b0d3255bfef95601890afd80709
adb536466977c49bebb6317891bffb77dc6e5823
Program 2:
<?php
$context = hash_init( "md5" );
$cp_context = hash_copy( $context );
echo hash_final( $context ), "\n" ;
hash_update( $cp_context , "GFG" );
echo hash_final( $cp_context ), "\n" ;
?>
|
Output:
d41d8cd98f00b204e9800998ecf8427e
eadc14b80cd2f247f467eb6c7f45fa9b
Reference: http://php.net/manual/en/function.hash-copy.php
Share your thoughts in the comments
Please Login to comment...