We now have a youtube channel. Subscribe!

PHP | hash_final() Function

PHP hash_final() 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_final() Function.

The built-in hash_final() function is used to return the final message digest.

A message digest is a hash with lowercase hexits generated using hash algorithms. It is predominantly used in securing the data so that the message or data that is sent is not changed.


Following below is the syntax to use this function -

hash_final ( HashContext $context [, bool $raw_output = FALSE ] ) : string

Parameter Details

Sr.NoParameter & Description

HashContext context

The hash context that you get using hash_init().



It takes true or false as value. If true it will give you lowercase hexits otherwise raw binary data. By default the value is true.

Return Value

It returns a string with calculated message digest of lowercase hexit. If the raw_output is set as FALSE, then the output is going be a string with raw binary data.

PHP Version

This PHP function works from PHP version greater than 5.1.2.


The following example illustrates the usage of the PHP hash_final() function -

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


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



The following example illustrates the usage of the built-in hash_final() function with the raw_output set as TRUE -

   $hash_context = hash_init('md5');
   hash_update($hash_context, 'Testing php');
   echo hash_final($hash_context, true); 

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP hash_hkdf() 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 tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain