• PHP Video Tutorials

PHP - Hash final() Function



Definition and Usage

The hash_final() function returns the final message digest.

A message digest is a hash with lowercase hexits (lowercase hexidecimals) that is generated using the hash algorithms. It is mainly used to secure the data so that the message or data send is not changed.

Syntax

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

Parameters

Sr.No Parameter & Description
1

HashContext context

The hash context that you get using hash_init().

2

raw_output

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 Values

PHP hash_final() function returns a string that has calculated message digest of hexits in lowercase. If false is passed as raw_output, the output will be a string with raw binary data.

PHP Version

This function will work from PHP Version greater than 5.1.2.

Example 1

Using hash_final −

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

Output

This will produce the following result −

e4310012c89a4b8479fd83694a2a3a31

Example 2

Using hash_final with raw_output as true −

<?php
   $hash_context = hash_init('md5');
   hash_update($hash_context, 'Testing php');
   echo hash_final($hash_context, true); 
?>
php_function_reference.htm
Advertisements