PHP | hash_copy() Function
January 24, 2021
Hello dear readers! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the PHP hash_copy() Function.
The built-in PHP hash_copy() function is used to copy the hashing context generated from hash_init().
The built-in PHP hash_copy() function is used to copy the hashing context generated from hash_init().
Syntax
Following below is the syntax to use this function -
hash_copy ( HashContext $context ) : HashContext
READ: PHP | algos() Function
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | HashContext context The hash context that you get using hash_init(). |
Return Value
This PHP function returns a copy of hash context. The hash context can be used along with other hash functions such as hash_update(), hash_update_file(), hash_final() and hash_update_stream().
PHP Version
This built-in function works from PHP version greater than 5.3.0.
Example1
Working with the hash_copy() and hash_init() functions -
<?php $hash_context = hash_init("md5"); hash_update($hash_context, "Welcome To Webdesigntutorialz"); $hash_copy= hash_copy($hash_context); echo hash_final($hash_context); echo "<br/>"; hash_update($hash_copy, "Welcome To Webdesigntutorialz"); echo hash_final($hash_copy); ?>
Output
When the above code is executed, it will produce the following result -
380d3ca1b0ab972f207209c076895310<br/>621058f8d42e78586b987c7b5233dc77
Example2
Working with the hash_copy() and sha256
<?php $hash_context = hash_init("sha256"); hash_update($hash_context, "Welcome To Webdesigntutorialz"); $hash_copy = hash_copy($hash_context); hash_update($hash_copy, "Welcome To Webdesigntutorialz"); echo hash_final($hash_copy); ?>
Output
When the above code is executed, it will produce the following result -
c37c7726bd39bab917ab8eb2143f914f9c37937bc48fb3b3ef11860867f93c20
READ: PHP | hash() Function
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we will discuss about the hash_equals() Function in PHP.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.
Thanks for reading and bye for now.