PHP Function Reference

PHP hash_final() Function



The PHP hash_final() function is used to finalize an incremental hash and return resulting 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(context, binary)

Parameters

context Required. Specify hashing context returned by hash_init().
binary Optional. If set to true, outputs raw binary data. Default is false which outputs lowercase hexits.

Return Value

Returns a string containing the calculated message digest as lowercase hexits unless binary is set to true in which case the raw binary representation of the message digest is returned.

Example: hash_final() example

The example below shows the usage of hash_final() function.

<?php
//initializing an incremental hashing context
$ctx = hash_init('sha1');

//updating context
hash_update($ctx, 'Hello World!');

//finalizing an incremental hash
//and returning resulting digest
echo hash_final($ctx);
?>

The output of the above code will be:

2ef7bde608ce5404e97d5f042f95f89f1c232871

❮ PHP Hash Reference