hash_final() – Finalize Incremental Hash and Return Digest

The hash_final() function completes an incremental hash operation in PHP, returning either a raw binary digest or a lowercase hexadecimal string based on the raw_output flag, with usage illustrated through a complete example.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
hash_final() – Finalize Incremental Hash and Return Digest

The hash_final() function ends an incremental hash operation and returns the resulting digest. Its signature is

string hash_final(resource $context[, bool $raw_output = false])

.

Parameters

context : The hash context resource returned by hash_init().

raw_output : When set to TRUE, the function returns the raw binary digest; when FALSE, it returns a lowercase hexadecimal string.

Return value

If $raw_output is TRUE, a binary string is returned; otherwise a hexadecimal string is returned.

Example

<?php
$ctx = hash_init('sha1');
hash_update($ctx, 'The quick brown fox jumped over the lazy dog.');
echo hash_final($ctx);
?>

Output

c0854fb9fb03c41cce3802cb0d220529e6eef94e
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Hashhash_final
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.