• PHP Video Tutorials

PHP - Hash update() Function



Definition and Usage

The hash_update() function will update the given data with the hash context.

Syntax

hash_update(HashContext $context , string $data ): bool

Parameters

Sr.No Parameter & Description
1

HashContext context

The hash context that you get using hash_init().

2

data

The data you want to mix with the hash context.

Return Values

PHP hash_update() function returns a boolean value i.e. true/false.

PHP Version

This function will work from PHP Version greater than 5.1.2.

Example 1

Using hash_update −

<?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_update with gost-crypto algorithm −

<?php
   $hash_context = hash_init('gost-crypto');
   hash_update($hash_context, 'Hello World');
   echo hash_final($hash_context);
?>

Output

This will produce the following result −

75ed15d84df84291c67fe07bf234ac69e92a9c2a378ee62f342af739e829eba9
php_function_reference.htm
Advertisements