PHP | hash_final() Function

PHP hash_final() Function

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

The built-in hash_final() function returns the final message digest.

A message digest is a hash with lowercase hexits generated using hash algorithms. It is mainly made use to secure 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

This built-in PHP function returns a string with a calculated message digest of lowercase hexits. If the raw_output is set as false, then the output will be a string with raw binary data.

PHP Version

This built-in 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 PHP 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 rounding up for this tutorial post. In our next tutorial, we will discuss about the hash_hkdf() Function in PHP.

Do feel free to ask your questions where necessary and i 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.