PHP | hash_update() Function

PHP hash_update() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP hash_update() Function.

The PHP hash_update() function updates the given data with the hash context.

Syntax

Following below is the syntax to use this function -

hash_update(HashContext $context , string $data ): bool


Parameter Details

Sr.NoParameter & Description
1

HashContext context

The hash context that you get using hash_init().

2

data

The data you want to mix with the hash context.


Return Value

This built-in PHP functions returns true or false.

PHP Version

This built-in PHP function works from PHP version greater than 5.1.2.

Example1

Following example illustrates the usage of the built-in hash_update() function -

<?php
   $hash_context = hash_init('md5');
   hash_update($hash_context, 'Testing php');
   hash_update($hash_context, ' hash functions.');
   echo hash_final($hash_context);
?>

Output

When the above code is executed, it will produce the following result -

e4310012c89a4b8479fd83694a2a3a31

Example2

Following example illustrates the usage of the built-in hash_update() function with the gost-crypto algo -

<?php
   $hash_context = hash_init('gost-crypto');
   hash_update($hash_context, 'Hello World');
   echo hash_final($hash_context);
?>

Output

When the above code is executed, it will produce the following result -

75ed15d84df84291c67fe07bf234ac69e92a9c2a378ee62f342af739e829eba9


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be studying about the PHP hash_update_file() Function.

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 tutorials delivered directly to your emails.

Thanks for reading and bye for now.