Example 1 — Finish an Incremental Hash
Add two pieces, then finish.
<?php
$ctx = hash_init('sha256');
hash_update($ctx, 'Hello, ');
hash_update($ctx, 'World');
$digest = hash_final($ctx);
echo $digest, PHP_EOL;
echo "Same as hash(): ", $digest === hash('sha256', 'Hello, World') ? "yes" : "no", PHP_EOL; How It Works
- Start a context. Pick the algorithm.
- Add two pieces. The order matters.
- Call `hash_final()`. It returns the hex hash.
- Compare with `hash()`. Both give the same value.

